Skip to content

tasks.py — Celery Task for Add-or-Update #43

@whisper67265

Description

@whisper67265

Problem

The add-or-update operation involves cloning repositories, scanning for translatable files, creating Weblate components, and importing translations — work that can take minutes. This must run asynchronously in a Celery worker, not in the HTTP request path. A Celery task definition is needed that receives the validated parameters from the view, reconstructs the user context in the worker, and delegates to the service layer.

Acceptance Criteria

  • src/boost_weblate/tasks.py defines an add_or_update Celery task decorated with @shared_task (or @app.task with the correct app reference)
  • The task accepts user_id, project_slug, repo_url, and languages as parameters
  • The task reconstructs the Weblate User object from user_id for permission-scoped operations
  • The task calls into services.py for the actual work, iterating per-language as needed
  • Errors in the service layer are caught, logged, and stored as the task result (not silently swallowed)
  • Task retry policy is configured (e.g., max_retries=3, default_retry_delay=60) for transient failures
  • The task ID returned to the client in the 202 response can be used to query task status via Celery's result backend

Implementation Notes

Use bind=True on the task so self is available for retry logic. The user context reconstruction should use django.contrib.auth.get_user_model().objects.get(pk=user_id) with a DoesNotExist guard. The per-language iteration pattern: loop over languages, calling services.process_language(user, project_slug, repo_url, lang) for each. Consider using self.update_state() to report progress per language.

References

  • Related files: src/boost_weblate/tasks.py, src/boost_weblate/services.py
  • Depends on: views.py (caller), services.py (callee)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions