Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark ResultStatus labels and DBTaskResult fields for translation (#94) #96

Merged
merged 2 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Generated by Django 4.2.14 on 2024-08-02 13:17

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("django_tasks_database", "0005_alter_dbtaskresult_priority_and_more"),
]

operations = [
migrations.AlterField(
model_name="dbtaskresult",
name="args_kwargs",
field=models.JSONField(verbose_name="args kwargs"),
),
migrations.AlterField(
model_name="dbtaskresult",
name="backend_name",
field=models.TextField(verbose_name="backend name"),
),
migrations.AlterField(
model_name="dbtaskresult",
name="enqueued_at",
field=models.DateTimeField(auto_now_add=True, verbose_name="enqueued at"),
),
migrations.AlterField(
model_name="dbtaskresult",
name="finished_at",
field=models.DateTimeField(null=True, verbose_name="finished at"),
),
migrations.AlterField(
model_name="dbtaskresult",
name="priority",
field=models.IntegerField(default=0, verbose_name="priority"),
),
migrations.AlterField(
model_name="dbtaskresult",
name="queue_name",
field=models.TextField(default="default", verbose_name="queue name"),
),
migrations.AlterField(
model_name="dbtaskresult",
name="result",
field=models.JSONField(default=None, null=True, verbose_name="result"),
),
migrations.AlterField(
model_name="dbtaskresult",
name="run_after",
field=models.DateTimeField(null=True, verbose_name="run after"),
),
migrations.AlterField(
model_name="dbtaskresult",
name="started_at",
field=models.DateTimeField(null=True, verbose_name="started at"),
),
migrations.AlterField(
model_name="dbtaskresult",
name="status",
field=models.CharField(
choices=[
("NEW", "New"),
("RUNNING", "Running"),
("FAILED", "Failed"),
("COMPLETE", "Complete"),
],
default="NEW",
max_length=8,
verbose_name="status",
),
),
migrations.AlterField(
model_name="dbtaskresult",
name="task_path",
field=models.TextField(verbose_name="task path"),
),
]
26 changes: 14 additions & 12 deletions django_tasks/backends/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from django.db.models.constraints import CheckConstraint
from django.utils import timezone
from django.utils.module_loading import import_string
from django.utils.translation import gettext_lazy as _
from typing_extensions import ParamSpec

from django_tasks.task import (
Expand Down Expand Up @@ -71,34 +72,35 @@ class DBTaskResult(GenericBase[P, T], models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)

status = models.CharField(
_("status"),
choices=ResultStatus.choices,
default=ResultStatus.NEW,
max_length=max(len(value) for value in ResultStatus.values),
)

enqueued_at = models.DateTimeField(auto_now_add=True)
started_at = models.DateTimeField(null=True)
finished_at = models.DateTimeField(null=True)
enqueued_at = models.DateTimeField(_("enqueued at"), auto_now_add=True)
started_at = models.DateTimeField(_("started at"), null=True)
finished_at = models.DateTimeField(_("finished at"), null=True)

args_kwargs = models.JSONField()
args_kwargs = models.JSONField(_("args kwargs"))

priority = models.IntegerField(default=DEFAULT_PRIORITY)
priority = models.IntegerField(_("priority"), default=DEFAULT_PRIORITY)

task_path = models.TextField()
task_path = models.TextField(_("task path"))

queue_name = models.TextField(default=DEFAULT_QUEUE_NAME)
backend_name = models.TextField()
queue_name = models.TextField(_("queue name"), default=DEFAULT_QUEUE_NAME)
backend_name = models.TextField(_("backend name"))

run_after = models.DateTimeField(null=True)
run_after = models.DateTimeField(_("run after"), null=True)

result = models.JSONField(default=None, null=True)
result = models.JSONField(_("result"), default=None, null=True)

objects = DBTaskResultQuerySet.as_manager()

class Meta:
ordering = [F("priority").desc(), F("run_after").desc(nulls_last=True)]
verbose_name = "Task Result"
verbose_name_plural = "Task Results"
verbose_name = _("Task Result")
verbose_name_plural = _("Task Results")
constraints = [
CheckConstraint(
check=Q(priority__range=(MIN_PRIORITY, MAX_PRIORITY)),
Expand Down
9 changes: 5 additions & 4 deletions django_tasks/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from asgiref.sync import async_to_sync, sync_to_async
from django.db.models.enums import TextChoices
from django.utils import timezone
from django.utils.translation import gettext_lazy as _
from typing_extensions import ParamSpec, Self

from .exceptions import ResultDoesNotExist
Expand All @@ -34,10 +35,10 @@


class ResultStatus(TextChoices):
NEW = ("NEW", "New")
RUNNING = ("RUNNING", "Running")
FAILED = ("FAILED", "Failed")
COMPLETE = ("COMPLETE", "Complete")
NEW = ("NEW", _("New"))
RUNNING = ("RUNNING", _("Running"))
FAILED = ("FAILED", _("Failed"))
COMPLETE = ("COMPLETE", _("Complete"))


T = TypeVar("T")
Expand Down
Loading