Coverage for portality / tasks / redis_huey.py: 100%
20 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-05 00:09 +0100
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-05 00:09 +0100
1from huey import RedisHuey, crontab
2from portality.core import app
4# every-day background jobs that take a few minutes each (like, bulk deletes and anything else requested by the user)
5# DEPRECATED
6main_queue = RedisHuey('doaj_main_queue',
7 host=app.config['REDIS_HOST'], port=app.config['REDIS_PORT'],
8 immediate=app.config.get("HUEY_IMMEDIATE", False))
10# jobs that might take a long time, like the harvester or the anon export, which can run for several hours
11# DEPRECATED
12long_running = RedisHuey('doaj_long_running',
13 host=app.config['REDIS_HOST'], port=app.config['REDIS_PORT'],
14 immediate=app.config.get("HUEY_IMMEDIATE", False))
17# short jobs to be run on demand from within the application
18events_queue = RedisHuey('doaj_events_queue',
19 host=app.config['REDIS_HOST'], port=app.config['REDIS_PORT'],
20 always_eager=app.config.get("HUEY_EAGER", False))
22# scheduled jobs that can run for several hours each
23scheduled_long_queue = RedisHuey('doaj_scheduled_long_queue',
24 host=app.config['REDIS_HOST'], port=app.config['REDIS_PORT'],
25 always_eager=app.config.get("HUEY_EAGER", False))
27# scheduled jobs that will typically run within a few minutes
28scheduled_short_queue = RedisHuey('doaj_scheduled_short_queue',
29 host=app.config['REDIS_HOST'], port=app.config['REDIS_PORT'],
30 always_eager=app.config.get("HUEY_EAGER", False))
32"""
33we put everything we want to be responsive onto the main_queue,
34and anything that would disrupt the main_queue by taking too
35long goes on long_running
36"""
39def schedule(action):
40 cfg = app.config.get("HUEY_SCHEDULE", {})
41 action_cfg = cfg.get(action)
42 if action_cfg is None:
43 raise RuntimeError(
44 "No configuration for scheduled action '{x}'. Define this in HUEY_SCHEDULE first then try again."
45 .format(x=action))
47 return crontab(**action_cfg)
50def configure(action):
51 cfg = app.config.get("HUEY_TASKS", {})
52 action_cfg = cfg.get(action)
53 if action_cfg is None:
54 raise RuntimeError(
55 "No task configuration for action '{x}'. Define this in HUEY_TASKS first then try again."
56 .format(x=action))
57 return action_cfg