Celery
Dispatches Python tasks to worker processes through a message broker, with configurable result backends.
- Downloads / mo
- 54.1M
- Stars
- 29.2K
- Last release
- 5.7.0
- License
- BSD-3-Clause
Strengths
- Supports several result backends. Choose a result store independently of the task broker.
- Retries selected exception types. Configure automatic retries with exception filters and backoff.
Limitations
- Results need a configured backend. Task return values are unavailable until a result backend is configured.
- Late acknowledgments can repeat work. Make tasks duplicate-safe when workers acknowledge after execution.
Quickstart
# tasks.py from celery import Celery app = Celery("tasks", broker="redis://localhost:6379/0") @app.task def add(x, y): return x + y # producer.py import tasks result = tasks.add.delay(1, 2)
Celery examples
def finish_import_project(self, request, project): """ Perform last steps to import a project into Read the Docs. - Add the user from request as maintainer - Run extra tasks that are needed before building the project - Trigger the initial build Direct upload projects skip the last two steps: Read the Docs never builds them, and the webhook and SSH key are not needed. It requires the Project was already saved into the DB. :param request: Django Request object :param project: Project instance just imported (already saved) """ project.users.add(request.user) log.info( "Project imported.", project_slug=project.slug, user_username=request.user.username, ) if project.is_direct_upload: return None update_docs, build = prepare_build(project) if (update_docs, build) == (None, None): return None tasks = self._get_post_import_tasks(project, request.user) # Build-isolated builds are dispatched by ``admit_queued_builds``, # running ``update_docs`` too would build it twice on two builders. if not project.has_feature(Feature.USE_BUILD_ISOLATED): tasks.append(update_docs) if tasks: chain(*tasks).apply_async()