forked from celery/django-celery-results
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
`models` module replaced by a `models` package containing an `abstract` module (for abstract models) and a `generic` module (for the default models, previously in the `models` module) --- Resolves celery#305 Fixes celery#314
- Loading branch information
1 parent
33bd77e
commit 74c1cc6
Showing
3 changed files
with
83 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .generic import ChordCounter, GroupResult, TaskResult | ||
|
||
__ALL__ = [ChordCounter, GroupResult, TaskResult] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
"""Database models.""" | ||
|
||
import json | ||
|
||
from celery.result import GroupResult as CeleryGroupResult | ||
from celery.result import result_from_tuple | ||
from django.conf import settings | ||
from django.db import models | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
from django_celery_results.models.abstract import ( | ||
AbstractGroupResult, | ||
AbstractTaskResult | ||
) | ||
|
||
|
||
class TaskResult(AbstractTaskResult): | ||
"""Task result/status.""" | ||
|
||
class Meta(AbstractTaskResult.Meta): | ||
"""Table information.""" | ||
|
||
abstract = False | ||
|
||
|
||
class ChordCounter(models.Model): | ||
"""Chord synchronisation.""" | ||
|
||
group_id = models.CharField( | ||
max_length=getattr( | ||
settings, | ||
"DJANGO_CELERY_RESULTS_TASK_ID_MAX_LENGTH", | ||
255), | ||
unique=True, | ||
verbose_name=_("Group ID"), | ||
help_text=_("Celery ID for the Chord header group"), | ||
) | ||
sub_tasks = models.TextField( | ||
help_text=_( | ||
"JSON serialized list of task result tuples. " | ||
"use .group_result() to decode" | ||
) | ||
) | ||
count = models.PositiveIntegerField( | ||
help_text=_( | ||
"Starts at len(chord header) and decrements after each task is " | ||
"finished" | ||
) | ||
) | ||
|
||
def group_result(self, app=None): | ||
"""Return the GroupResult of self. | ||
Arguments: | ||
--------- | ||
app (Celery): app instance to create the GroupResult with. | ||
""" | ||
return CeleryGroupResult( | ||
self.group_id, | ||
[result_from_tuple(r, app=app) | ||
for r in json.loads(self.sub_tasks)], | ||
app=app | ||
) | ||
|
||
|
||
class GroupResult(AbstractGroupResult): | ||
"""Task Group result/status.""" | ||
|
||
class Meta(AbstractGroupResult.Meta): | ||
"""Table information.""" | ||
|
||
abstract = False |