-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtasks.py
30 lines (24 loc) · 817 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
import os
import redis
from celery.utils.log import get_task_logger
import logging
from zimbalaka import celery
from zimbalaka.utils import zimit
class CLogger:
def __init__(self, uid):
self.r = redis.StrictRedis(host='localhost', port=6379, db=0)
self.uid = uid
def log(self, record):
self.r.append( 'task:{0}:log'.format(self.uid), record+"\n")
def count(self, percent):
self.r.set('task:{0}:count'.format(self.uid), percent)
@celery.task(bind=True)
def prepare_zim(self, title, articles, cats, url):
'''task that prepares the zim file'''
c = CLogger( self.request.id )
zimfile = zimit(title, articles, cats, url, c)
return zimfile
@celery.task(ignore_result=True)
def delete_zim(zimfile):
'''task to delete the folder'''
os.remove(zimfile)