Skip to content

Commit

Permalink
package rename
Browse files Browse the repository at this point in the history
  • Loading branch information
domdinicola committed Sep 30, 2024
1 parent d96981b commit 9a1d7ca
Show file tree
Hide file tree
Showing 16 changed files with 39 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: celery_model
POSTGRES_DB: django_celery_boost
defaults:
run:
shell: bash
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# django-celery-model
# django-celery-boost

[![Test](https://github.com/unicef/django-celery-model/actions/workflows/test.yml/badge.svg)](https://github.com/unicef/django-celery-model/actions/workflows/test.yml)
[![Lint](https://github.com/unicef/django-celery-model/actions/workflows/lint.yml/badge.svg)](https://github.com/unicef/django-celery-model/actions/workflows/lint.yml)
[![Documentation](https://github.com/unicef/django-celery-model/actions/workflows/docs.yml/badge.svg)](https://github.com/unicef/django-celery-model/actions/workflows/docs.yml)
[![codecov](https://codecov.io/github/unicef/django-celery-model/graph/badge.svg?token=L7HA5PJ45B)](https://codecov.io/github/unicef/django-celery-model)
[![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)


django-celery-model is a small Django Abstract Model that provides some useful methods to manage
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-models has been developed as part of the UNICEF HOPE project, read more at https://unicef.github.io/hope-documentation/
Django-celery-boost has been developed as part of the UNICEF HOPE project, read more at https://unicef.github.io/hope-documentation/

---

Expand Down
2 changes: 1 addition & 1 deletion docs/src/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Install [uv](https://docs.astral.sh/uv/)

git clone ..
uv venv create --python 3.12
uv venv .venv --python 3.12
source .venv/bin/activate
uv sync

Expand Down
4 changes: 2 additions & 2 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
title: Documentation
---

django-celery-models is a small Django Abstract Model that provides some useful methods to manage
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-models is part of the UNICEF HOPE project, read more [here](https://unicef.github.io/hope-documentation/).
django-celery-boost is part of the UNICEF HOPE project, read more [here](https://unicef.github.io/hope-documentation/).


!!! warning
Expand Down
6 changes: 3 additions & 3 deletions docs/src/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Install
---

django-celery-models is a small Django Abstract Model that provides some useful methods to manage
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.


Expand All @@ -13,7 +13,7 @@ Models that represents the "context" of a Celery task.

## Install

pip install django-celery-model
pip install django-celery-boost

In your `settings.py`:

Expand All @@ -22,7 +22,7 @@ In your `settings.py`:
INSTALLED_APPS = [
...
"admin_extra_buttons",
"celery_model",
"django_celery_boost",
]

CELERY_BROKER_URL=redis://
Expand Down
2 changes: 1 addition & 1 deletion docs/src/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## CeleryTaskModel

::: celery_model.models.CeleryTaskModel
::: django_celery_boost.models.CeleryTaskModel
handler: python
options:
annotations_path: brief
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "django-celery-model"
name = "django-celery-boost"
version = "0.1.0"
description = "Django AnstractModel to work with Celery"
description = "Django Anstract Model to work with Celery"
readme = "README.md"
requires-python = ">=3.10"
dependencies = [
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.http import HttpRequest, HttpResponse
from django.shortcuts import render

from celery_model.models import CeleryTaskModel
from django_celery_boost.models import CeleryTaskModel


class CeleryTaskModelAdmin(ExtraButtonsMixin, admin.ModelAdmin):
Expand Down Expand Up @@ -49,7 +49,7 @@ def celery_inspect(self, request: HttpRequest, pk: int) -> HttpResponse:
[
"admin/%s/%s/inspect.html" % (self.opts.app_label, self.opts.model_name),
"admin/%s/inspect.html" % self.opts.app_label,
"admin/celery_model/inspect.html",
"admin/django_celery_boost/inspect.html",
],
ctx,
)
Expand Down
27 changes: 14 additions & 13 deletions src/celery_model/models.py → src/django_celery_boost/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class Meta:
def celery_app(cls) -> "celery.app.base.Celery":
if not cls._celery_app:
from celery import current_app as app

cls._celery_app = app
return cls._celery_app

Expand All @@ -81,7 +82,7 @@ def check(cls, **kwargs):
errors.append(
checks.Error(
"'%s' does not have a Celery task name." % cls._meta,
id="celery_model.E001",
id="django_celery_boost.E001",
)
)
else:
Expand All @@ -91,7 +92,7 @@ def check(cls, **kwargs):
errors.append(
checks.Error(
"'%s': Cannot import Celery task '%s'" % (cls._meta, cls.celery_task_name),
id="celery_model.E002",
id="django_celery_boost.E002",
)
)
else:
Expand All @@ -100,7 +101,7 @@ def check(cls, **kwargs):
errors.append(
checks.Error(
"'%s' is using a non registered Celery task. (%s)" % (cls._meta, cls.celery_task_name),
id="celery_model.E003",
id="django_celery_boost.E003",
)
)

Expand Down Expand Up @@ -141,7 +142,7 @@ def celery_queue_entries(cls) -> "Generator":

@classmethod
def celery_queue_info(cls) -> "dict[str, int]":
""" Returns information about the Queue
"""Returns information about the Queue
Returns:
Dictionary with size,pendig, canceled, revoked tasks
Expand Down Expand Up @@ -176,15 +177,15 @@ def celery_queue_info(cls) -> "dict[str, int]":

@property
def async_result(self) -> "AsyncResult|None":
""" Returns the AsyncResult object of the current instance"""
"""Returns the AsyncResult object of the current instance"""
if self.curr_async_result_id:
return AsyncResult(self.curr_async_result_id)
else:
return None

@property
def queue_entry(self) -> "dict[str, Any]":
""" Returns the queue entry of the current instance"""
"""Returns the queue entry of the current instance"""
if self.async_result:
for task in self.celery_queue_entries():
j = json.loads(task)
Expand All @@ -195,7 +196,7 @@ def queue_entry(self) -> "dict[str, Any]":

@property
def task_info(self) -> "dict[str, Any]":
""" Returns the task meta information of the current instance
"""Returns the task meta information of the current instance
Returns:
Dictionary with task information
Expand Down Expand Up @@ -233,11 +234,11 @@ def task_info(self) -> "dict[str, Any]":

@classproperty
def task_handler(cls: "type[CeleryTaskModel]") -> "Callable[[Any], Any]":
""" Return the task assigned to this model """
"""Return the task assigned to this model"""
return import_string(cls.celery_task_name)

def is_queued(self) -> bool:
""" Check if the job is queued """
"""Check if the job is queued"""
with self.celery_app.pool.acquire(block=True) as conn:
tasks = conn.default_channel.client.lrange(self.celery_task_queue, 0, -1)
for task in tasks:
Expand All @@ -256,7 +257,7 @@ def is_canceled(self) -> bool:

@property
def status(self) -> str:
""" Returns the task status querying Celery API"""
"""Returns the task status querying Celery API"""
try:
if self.curr_async_result_id:
if self.is_canceled():
Expand All @@ -275,7 +276,7 @@ def status(self) -> str:
return str(e)

def queue(self) -> str | None:
""" Queue the record processing"""
"""Queue the record processing"""
if self.status not in self.SCHEDULED:
res = self.task_handler.delay(self.pk, self.version)
with concurrency_disable_increment(self):
Expand All @@ -285,7 +286,7 @@ def queue(self) -> str | None:
return None

def terminate(self) -> str:
""" Revoke the task. Does not need Running workers"""
"""Revoke the task. Does not need Running workers"""
st = self.UNKNOWN
if self.status in ["QUEUED", "PENDING"]:
with self.celery_app.pool.acquire(block=True) as conn:
Expand All @@ -297,7 +298,7 @@ def terminate(self) -> str:
for task_json in self.celery_queue_entries():
task = json.loads(task_json)
try:
if task.get('headers').get('id') == self.curr_async_result_id:
if task.get("headers").get("id") == self.curr_async_result_id:
conn.default_channel.client.lrem(self.celery_task_queue, 1, task_json)
break
except AttributeError: # pragma: no cover
Expand Down
2 changes: 1 addition & 1 deletion tests/.coveragerc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[run]
branch = True
source = src
source_pkgs = celery_model
source_pkgs = django_celery_boost
relative_files = True
# partial_branches =
omit =
Expand Down
2 changes: 1 addition & 1 deletion tests/demoapp/demo/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from demo.models import Job
from django.contrib import admin

from celery_model.admin import CeleryTaskModelAdmin
from django_celery_boost.admin import CeleryTaskModelAdmin


@admin.register(Job)
Expand Down
2 changes: 1 addition & 1 deletion tests/demoapp/demo/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.db import models

from celery_model.models import CeleryTaskModel
from django_celery_boost.models import CeleryTaskModel


class Job(CeleryTaskModel, models.Model):
Expand Down
4 changes: 2 additions & 2 deletions tests/demoapp/demo/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"django.contrib.staticfiles",
# "django_celery_beat",
"admin_extra_buttons",
"celery_model",
"django_celery_boost",
"demo.apps.Config",
]

Expand Down Expand Up @@ -80,7 +80,7 @@
# "ENGINE": "django.db.backends.sqlite3",
# "NAME": "db.sqlite3",
"ENGINE": "django.db.backends.postgresql",
"NAME": "celery_model",
"NAME": "django_celery_boost",
"HOST": os.environ.get("DB_HOST", "localhost"),
"PORT": os.environ.get("DB_PORT", "5432"),
"USER": os.environ.get("DB_USER", "postgres"),
Expand Down
4 changes: 1 addition & 3 deletions tests/test_celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@

@pytest.fixture(scope="session")
def celery_config():
return {"broker_url": os.environ['CELERY_BROKER_URL'],
"result_backend": os.environ['CELERY_BROKER_URL']
}
return {"broker_url": os.environ["CELERY_BROKER_URL"], "result_backend": os.environ["CELERY_BROKER_URL"]}


@pytest.fixture(scope="session")
Expand Down

0 comments on commit 9a1d7ca

Please sign in to comment.