Skip to content

Commit 6fee8b7

Browse files
committed
Merge pull request #120 from codefordurham/feature/dconc-task
Add background task to import Durham data nightly
2 parents 4073588 + 24ccd48 commit 6fee8b7

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

eatsmart/locations/durham/tasks.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from logging import getLogger
2+
3+
from eatsmart.celery import app
4+
from eatsmart.locations.durham import api
5+
6+
7+
logger = getLogger(__file__)
8+
9+
10+
@app.task
11+
def import_durham_data():
12+
"""Import Durham data"""
13+
logger.info("Starting Durham Import")
14+
api.EstablishmentImporter().run()
15+
api.InspectionImporter().run()
16+
api.ViolationImporter().run()
17+
logger.info("Finished Durham Import")

eatsmart/settings/base.py

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Django settings for eatsmart project.
22
import os
3+
from celery.schedules import crontab
4+
35

46
PROJECT_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
57
PROJECT_ROOT = os.path.abspath(os.path.join(PROJECT_PATH, os.pardir))
@@ -222,3 +224,10 @@
222224
# Default user location
223225
LATITUDE = 35.988611
224226
LONGITUDE = -78.907222
227+
228+
CELERYBEAT_SCHEDULE = {
229+
'import-durham-data': {
230+
'task': 'eatsmart.locations.durham.tasks.import_durham_data',
231+
'schedule': crontab(minute=0, hour=0), # Execute daily at midnight
232+
},
233+
}

0 commit comments

Comments
 (0)