Coverage for portality/tasks/redis_huey.py: 100%

17 statements  

« prev     ^ index     » next       coverage.py v7.17.3, created at 2026-11-20 13:43 +0000

1from huey import RedisHuey, crontab 

2from portality.core import app 

3 

4# short jobs to be run on demand from within the application 

5events_queue = RedisHuey('doaj_events_queue', 

6 host=app.config['REDIS_HOST'], port=app.config['REDIS_PORT'], 

7 always_eager=app.config.get("HUEY_EAGER", False)) 

8 

9# scheduled jobs that can run for several hours each 

10scheduled_long_queue = RedisHuey('doaj_scheduled_long_queue', 

11 host=app.config['REDIS_HOST'], port=app.config['REDIS_PORT'], 

12 always_eager=app.config.get("HUEY_EAGER", False)) 

13 

14# scheduled jobs that will typically run within a few minutes 

15scheduled_short_queue = RedisHuey('doaj_scheduled_short_queue', 

16 host=app.config['REDIS_HOST'], port=app.config['REDIS_PORT'], 

17 always_eager=app.config.get("HUEY_EAGER", False)) 

18 

19 

20def schedule(action): 

21 cfg = app.config.get("HUEY_SCHEDULE", {}) 

22 action_cfg = cfg.get(action) 

23 if action_cfg is None: 

24 raise RuntimeError( 

25 "No configuration for scheduled action '{x}'. Define this in HUEY_SCHEDULE first then try again." 

26 .format(x=action)) 

27 

28 return crontab(**action_cfg) 

29 

30 

31def configure(action): 

32 cfg = app.config.get("HUEY_TASKS", {}) 

33 action_cfg = cfg.get(action) 

34 if action_cfg is None: 

35 raise RuntimeError( 

36 "No task configuration for action '{x}'. Define this in HUEY_TASKS first then try again." 

37 .format(x=action)) 

38 return action_cfg