forked from fecgov/openFEC
/
cron.py
executable file
·43 lines (30 loc) · 884 Bytes
/
cron.py
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
#!/usr/bin/env python
"""Run background tasks in a crontab-like system using celery beat. Celery does
not daemonize itself, so this script should be run in a subprocess or managed
using supervisor or a similar tool.
Simple invocation: ::
$ ./cron.py
Customizable invocation: ::
celery worker -app cron --beat
"""
import celery
from celery.schedules import crontab
import manage
app = celery.Celery('cron')
app.conf.update(
BROKER_URL='sqla+sqlite:///beat.sqlite',
CELERY_IMPORTS=('cron', ),
CELERYBEAT_SCHEDULE={
'refresh': {
'task': 'cron.refresh',
'schedule': crontab(minute=0, hour=0),
},
}
)
@app.task
def refresh():
with manage.app.test_request_context():
manage.update_aggregates()
manage.refresh_materialized()
if __name__ == '__main__':
app.worker_main(['worker', '--beat'])