Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skipped tasks support #59

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion django_dramatiq/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,21 @@ def before_process_message(self, broker, message):
queue_name=message.queue_name,
)

def after_process_message(self, broker, message, *, result=None, exception=None):
def after_skip_message(self, broker, message):
from .models import Task
self.after_process_message(broker, message, task_status=Task.STATUS_SKIPPED)

def after_process_message(self, broker, message, *, result=None, exception=None, task_status=None):
from .models import Task

status = Task.STATUS_DONE
if exception is not None:
status = Task.STATUS_FAILED
status = task_status
if status is None:
status = Task.STATUS_DONE
if exception is not None:
status = Task.STATUS_FAILED

LOGGER.debug("Updating Task from message %r.", message.message_id)
Task.tasks.create_or_update_from_message(
Expand Down
2 changes: 2 additions & 0 deletions django_dramatiq/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ class Task(models.Model):
STATUS_RUNNING = "running"
STATUS_FAILED = "failed"
STATUS_DONE = "done"
STATUS_SKIPPED = "skipped"
STATUSES = [
(STATUS_ENQUEUED, "Enqueued"),
(STATUS_DELAYED, "Delayed"),
(STATUS_RUNNING, "Running"),
(STATUS_FAILED, "Failed"),
(STATUS_DONE, "Done"),
(STATUS_SKIPPED, "Skipped"),
]

id = models.UUIDField(primary_key=True, editable=False)
Expand Down