Skip to content

Commit

Permalink
updates docs
Browse files Browse the repository at this point in the history
  • Loading branch information
saxix committed Oct 1, 2024
1 parent 9fd1538 commit c4c4885
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 6 deletions.
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@

[![Test](https://github.com/unicef/django-celery-boost/actions/workflows/test.yml/badge.svg)](https://github.com/unicef/django-celery-boost/actions/workflows/test.yml)
[![Lint](https://github.com/unicef/django-celery-boost/actions/workflows/lint.yml/badge.svg)](https://github.com/unicef/django-celery-boost/actions/workflows/lint.yml)
[![Documentation](https://github.com/unicef/django-celery-boost/actions/workflows/docs.yml/badge.svg)](https://github.com/unicef/django-celery-boost/actions/workflows/docs.yml)
[![codecov](https://codecov.io/github/unicef/django-celery-boost/graph/badge.svg?token=L7HA5PJ45B)](https://codecov.io/github/unicef/django-celery-model)
[![Documentation](https://github.com/unicef/django-celery-boost/actions/workflows/docs.yml/badge.svg)](https://unicef.github.io/django-celery-boost/)
[![codecov](https://codecov.io/github/unicef/django-celery-boost/graph/badge.svg?token=L7HA5PJ45B)](https://codecov.io/github/unicef/django-celery-boost)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/django-celery-boost)](https://pypi.org/project/django-celery-boost/)


django-celery-boost is a small Django Abstract Model that provides some useful methods to manage
Models that represents the "context" of a Celery task.

## Links

- Documentation https://unicef.github.io/django-celery-boost/
- Source Code - https://github.com/unicef/django-celery-boost
- Pypi - https://pypi.org/project/django-celery-boost/

Django-celery-boost has been developed as part of the UNICEF HOPE project, read more at https://unicef.github.io/hope-documentation/

---


## Features
Expand All @@ -22,3 +26,11 @@ Django-celery-boost has been developed as part of the UNICEF HOPE project, read
- Revoke tasks with to running workers
- Retrieve task position in the queue
- Admin integration to inspect task status (running/result/error)



---

Django-celery-boost has been developed as part of the UNICEF HOPE project, read more at https://unicef.github.io/hope-documentation/

---
7 changes: 5 additions & 2 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ title: Documentation
django-celery-boost is a small Django Abstract Model that provides some useful methods to manage
Models that represents the "context" of a Celery task.

django-celery-boost is part of the UNICEF HOPE project, read more [here](https://unicef.github.io/hope-documentation/).


!!! warning

Expand All @@ -20,3 +18,8 @@ django-celery-boost is part of the UNICEF HOPE project, read more [here](https:/
- Revoke tasks with to running workers
- Retrieve task position in the queue
- Admin integration to inspect task status (running/result/error)


!!! note

django-celery-boost is part of the UNICEF HOPE project, read more [here](https://unicef.github.io/hope-documentation/).
33 changes: 33 additions & 0 deletions docs/src/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,36 @@ In your `settings.py`:
CELERY_TASK_IGNORE_RESULT = False
CELERY_TASK_DEFAULT_QUEUE = "my_tasks_queue"
CELERY_TASK_REVOKED_QUEUE = "my_revoked_queue"

## Setup your application


In your `tasks.py`

from celery import current_app

@current_app.task(bind=True)
def process_job(self, pk, version=None):
job = Job.objects.get(pk=pk)
...

In your `models.py`


class Job(CeleryTaskModel, models.Model):
...

celery_task_name = "demo.tasks.process_job"

# optional in csse
celery_task_queue = ...
celery_task_revoked_queue = ...

To "run" your task:

j = Job.objecs.get(pk=1)
j.queue()

To "cancel" it:

j.terminate()
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,4 @@ plugins:

watch:
- docs/
- src/
15 changes: 15 additions & 0 deletions src/django_celery_boost/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ class CeleryManager:


class CeleryTaskModel(models.Model):
"""
Attributes:
flight_speed The maximum speed that such a bird can attain.
nesting_grounds The locale where these birds congregate to reproduce.
"""

class Meta:
abstract = True

Expand Down Expand Up @@ -63,8 +70,16 @@ class Meta:
result = models.CharField(max_length=100, default="", blank=True, null=True)

celery_task_name: str = ""
"FQN of the task processing this Model's instances"

celery_task_queue: str = settings.CELERY_TASK_DEFAULT_QUEUE
"""Name of the queue this task connected to.
Only need to be specified if different from `settings.CELERY_TASK_DEFAULT_QUEUE`"""

celery_task_revoked_queue: str = settings.CELERY_TASK_REVOKED_QUEUE
"""Name of the queue where revoked tasks are stored.
Only need to be specified if different from `settings.CELERY_TASK_REVOKED_QUEUE`"""

_celery_app: Optional[Celery] = None

@classproperty
Expand Down

0 comments on commit c4c4885

Please sign in to comment.