/
tasks.py
35 lines (27 loc) · 899 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 future import standard_library
standard_library.install_aliases()
from celery import Celery
from time import sleep
import logging
import config as cfg
from docs import initvars,P
import subprocess
initvars(cfg)
from subprocess import getstatusoutput as gso
celery = Celery('tasks',broker=cfg.REDIS_BROKER)
def db(function):
""" this decorator acquires a db connection from the pool as well as a cursor from the connection and passes both on to its client. """
def wrap_function(*args, **kwargs):
with P as p:
kwargs['P']=p
kwargs['C']=p.cursor()
return function(*args, **kwargs)
return wrap_function
@celery.task
@db
def notifications(adm,tid,P,C):
from notif import notification_logic
notification_logic(P,C,tid=tid,supress=False,notify=True)
@celery.task
def changes_to_feed():
get_changes(show=False,feed=True)