Repository navigation
Expand file tree
/
Copy pathcli.py
More file actions
51 lines (41 loc) · 1.3 KB
/
Copy pathcli.py
File metadata and controls
51 lines (41 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import click
from flask.cli import with_appcontext
@click.group()
def rq_group():
"""RQ management commands."""
pass
@rq_group.command(context_settings=dict(
ignore_unknown_options=True,
allow_extra_args=True,
))
@click.pass_context
@with_appcontext
def worker(ctx):
"""Start an RQ worker with Flask context."""
from extensions import rq
# Check for --with-scheduler in extra args
with_scheduler = '--with-scheduler' in ctx.args
# Get worker from extension with proper context handling
# 'snapshots' is ordered first so interactive snapshot renders are not
# stuck behind a backlog of maintenance jobs.
worker = rq.get_worker('snapshots', 'default', 'maintenance')
worker.work(with_scheduler=with_scheduler)
@rq_group.command()
@with_appcontext
def cron():
"""Start the RQ cron daemon with explicit job registration."""
from extensions import rq
from tasks import prune_tasks, prune_syncs
# Get scheduler from extension (explicitly uses the connection)
cron_scheduler = rq.get_scheduler()
cron_scheduler.register(
prune_tasks,
queue_name='maintenance',
cron='0 0 * * *'
)
cron_scheduler.register(
prune_syncs,
queue_name='maintenance',
cron='30 0 * * *'
)
cron_scheduler.start()