-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtasks.py
More file actions
63 lines (48 loc) · 1.43 KB
/
tasks.py
File metadata and controls
63 lines (48 loc) · 1.43 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
52
53
54
55
56
57
58
59
60
61
62
63
__author__ = 'jcranwellward'
import os
from celery import Celery
from celery.schedules import crontab
from manage import app, import_ai, update_sites
CELERYBEAT_SCHEDULE = {
# Executes import every 4 hours
'import-ai-everyday': {
'task': 'tasks.run_import',
'schedule': crontab(hour='*/4'),
},
}
def make_celery(app):
celery = Celery(app.import_name, broker=app.config['CELERY_BROKER_URL'])
celery.conf.update(app.config)
celery.conf.CELERYBEAT_SCHEDULE = CELERYBEAT_SCHEDULE
TaskBase = celery.Task
class ContextTask(TaskBase):
abstract = True
def __call__(self, *args, **kwargs):
with app.app_context():
return TaskBase.__call__(self, *args, **kwargs)
celery.Task = ContextTask
return celery
celery = make_celery(app)
@celery.task
def run_import():
dbs = os.environ.get('AI_DBS')
username = os.environ.get('AI_USERNAME')
password = os.environ.get('AI_PASSWORD')
if dbs:
import_ai(dbs, username, password)
@celery.task
def run_sites_update(
api_key,
domain,
table_name,
site_type,
name_col,
code_col,
target_list):
update_sites(api_key=api_key,
domain=domain,
list_name=table_name,
site_type=site_type,
name_col=name_col,
code_col=code_col,
target_list=target_list)