File: urls.py

package info (click to toggle)
python-django-celery-results 2.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 696 kB
  • sloc: python: 2,373; makefile: 312; sh: 7; sql: 2
file content (86 lines) | stat: -rw-r--r-- 2,141 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
"""URLs defined for celery.

* ``/$task_id/done/``
    URL to :func:`~celery.views.is_successful`.
* ``/$task_id/status/``
    URL  to :func:`~celery.views.task_status`.
"""
import warnings

from django.conf import settings
from django.urls import path, register_converter

from . import views


class TaskPatternConverter:
    """Custom path converter for task & group id's.

    They are slightly different from the built `uuid`
    """

    regex = r'[\w\d\-\.]+'

    def to_python(self, value):
        """Convert url to python value."""
        return str(value)

    def to_url(self, value):
        """Convert python value into url, just a string."""
        return value


register_converter(TaskPatternConverter, 'task_pattern')

urlpatterns = [
    path(
        'task/done/<task_pattern:task_id>/',
        views.is_task_successful,
        name='celery-is_task_successful'
    ),
    path(
        'task/status/<task_pattern:task_id>/',
        views.task_status,
        name='celery-task_status'
    ),
    path(
        'group/done/<task_pattern:group_id>/',
        views.is_group_successful,
        name='celery-is_group_successful'
    ),
    path(
        'group/status/<task_pattern:group_id>/',
        views.group_status,
        name='celery-group_status'
    ),
]

if getattr(settings, 'DJANGO_CELERY_RESULTS_ID_FIRST_URLS', True):
    warnings.warn(
        "ID first urls depricated, use noun first urls instead."
        "Will be removed in 2022.",
        DeprecationWarning
    )

    urlpatterns += [
        path(
            '<task_pattern:task_id>/done/',
            views.is_task_successful,
            name='celery-is_task_successful'
        ),
        path(
            '<task_pattern:task_id>/status/',
            views.task_status,
            name='celery-task_status'
        ),
        path(
            '<task_pattern:group_id>/group/done/',
            views.is_group_successful,
            name='celery-is_group_successful'
        ),
        path(
            '<task_pattern:group_id>/group/status/',
            views.group_status,
            name='celery-group_status'
        ),
    ]