Adds task groups

* task now takes an optional keyword `group`
* added result_group()  and fetch_group()
* added group column to Success admin
* group column in searchable
* added `name` field to Schedules
* Scheduled tasks take schedule name as group
This commit is contained in:
Ilan
2015-07-18 17:20:50 +02:00
parent 05c8f3bc16
commit c127604f10
7 changed files with 85 additions and 17 deletions
+31 -5
View File
@@ -25,20 +25,27 @@ def async(func, *args, **kwargs):
# optional list_key
list_key = kwargs.pop('list_key', Conf.Q_LIST)
# optional redis connection
r = kwargs.pop('redis', redis_client)
redis = kwargs.pop('redis', redis_client)
# optional sync mode
s = kwargs.pop('sync', False)
sync = kwargs.pop('sync', False)
# optional group
group = kwargs.pop('group', None)
# get an id
tag = uuid()
# build the task package
task = {'id': tag[1], 'name': tag[0], 'func': func, 'hook': hook, 'args': args, 'kwargs': kwargs,
task = {'id': tag[1], 'name': tag[0], 'func': func, 'args': args, 'kwargs': kwargs,
'started': timezone.now()}
# add optionals
if hook:
task['hook'] = hook
if group:
task['group'] = group
# sign it
pack = signing.SignedPackage.dumps(task)
if s:
if sync:
return _sync(task['id'], pack)
# push it
r.rpush(list_key, pack)
redis.rpush(list_key, pack)
logger.debug('Pushed {}'.format(tag))
return task['id']
@@ -83,6 +90,15 @@ def result(task_id):
return Task.get_result(task_id)
def result_group(group_id):
"""
returns a list of results for a task group
:param str group_id: the group id
:return: list or results
"""
return Task.get_group_result(group_id)
def fetch(task_id):
"""
Returns the processed task
@@ -94,6 +110,16 @@ def fetch(task_id):
return Task.get_task(task_id)
def fetch_group(group_id):
"""
Returns a list of Tasks for a task group
:param str group_id: the group id
:return: list of Tasks
"""
return Task.get_task_group(group_id)
def _sync(task_id, pack):
"""
Simulates a package travelling through the cluster.