-
Notifications
You must be signed in to change notification settings - Fork 5
/
tasks.py
32 lines (26 loc) · 860 Bytes
/
tasks.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
from app import db, app
from celery.signals import task_postrun
from app import create_celery_app
from celery.task.schedules import crontab
from celery.decorators import periodic_task
from celery.utils.log import get_task_logger
from datetime import datetime
from feeder.feed import Feed
import requests
celery = create_celery_app(app)
logger = get_task_logger(__name__)
@celery.task
def send_event_notification():
''' send mail to the recipients '''
print "sent the mail"
@periodic_task(run_every=(crontab(hour="*", minute="1", day_of_week="*")))
def pull_feeds():
logger.info("Start task")
now = datetime.now()
f = Feed()
results = f.process_all()
logger.info("pulled feeds")
logger.info("Task finished: total inserted %i" % len(results))
@task_postrun.connect
def close_session(*args, **kwargs):
db.session.remove()