Created
October 21, 2022 10:30
-
-
Save absent1706/b1015a7d4230ed757e5095c090a54769 to your computer and use it in GitHub Desktop.
run and retry Celery tasks synchronously
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
""" | |
useful for local development and unit tests when tasks are run syncronously | |
""" | |
from your_app.settings import TESTING | |
from celery import Task | |
from celery.canvas import Signature | |
def run_task(task_signature: Signature): | |
if TESTING: | |
task_signature() | |
else: | |
task_signature.delay() | |
def retry_task(task: Task, task_kwargs, retry_kwargs): | |
if TESTING: | |
task.request.retries += 1 | |
task(**task_kwargs) | |
else: | |
task.retry(**retry_kwargs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment