mirror of
https://github.com/django-q2/django-q2.git
synced 2026-09-24 15:58:12 +08:00
adds count_group() and delete_group()
This commit is contained in:
@@ -4,7 +4,7 @@ import sys
|
||||
myPath = os.path.dirname(os.path.abspath(__file__))
|
||||
sys.path.insert(0, myPath)
|
||||
|
||||
from .tasks import async, schedule, result, result_group, fetch, fetch_group
|
||||
from .tasks import async, schedule, result, result_group, fetch, fetch_group, count_group, delete_group
|
||||
from .models import Task, Schedule, Success, Failure
|
||||
from .cluster import Cluster
|
||||
|
||||
|
||||
@@ -37,6 +37,19 @@ class Task(models.Model):
|
||||
values = Task.objects.filter(group=group_id).values_list('result', flat=True)
|
||||
return [dbsafe_decode(t) for t in values]
|
||||
|
||||
@staticmethod
|
||||
def get_group_count(group_id, failures=False):
|
||||
if failures:
|
||||
return Failure.objects.filter(group=group_id).count()
|
||||
return Task.objects.filter(group=group_id).count()
|
||||
|
||||
@staticmethod
|
||||
def delete_group(group_id, objects=False):
|
||||
group = Task.objects.filter(group=group_id)
|
||||
if objects:
|
||||
return group.delete()
|
||||
return group.update(group_id=None)
|
||||
|
||||
@staticmethod
|
||||
def get_task(task_id):
|
||||
if len(task_id) == 32 and Task.objects.filter(id=task_id).exists():
|
||||
|
||||
@@ -123,6 +123,26 @@ def fetch_group(group_id):
|
||||
return Task.get_task_group(group_id)
|
||||
|
||||
|
||||
def count_group(group_id, failures=False):
|
||||
"""
|
||||
:param str group_id: the group id
|
||||
:param bool failures: Returns failure count if True
|
||||
:return: the number of tasks/results in a group
|
||||
:rtype: int
|
||||
"""
|
||||
return Task.get_group_count(group_id, failures)
|
||||
|
||||
|
||||
def delete_group(group_id, tasks=False):
|
||||
"""
|
||||
:param str group_id: the group id
|
||||
:param bool tasks: If set to True this will also delete the group tasks.
|
||||
Otherwise just the group label is removed.
|
||||
:return:
|
||||
"""
|
||||
return Task.delete_group(group_id, tasks)
|
||||
|
||||
|
||||
def _sync(task_id, pack):
|
||||
"""
|
||||
Simulates a package travelling through the cluster.
|
||||
|
||||
Reference in New Issue
Block a user