-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.py
122 lines (117 loc) · 4.59 KB
/
settings.py
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import os
from django.urls import reverse_lazy
from django.utils.translation import gettext_lazy as _
def extend_superapp_settings(main_settings):
main_settings['INSTALLED_APPS'] = \
[
'django_celery_beat',
'django_celery_results',
] + main_settings['INSTALLED_APPS'] + [
'superapp.apps.tasks',
]
main_settings['UNFOLD']['TABS'] += [
{
"models": [
"django_celery_beat.clockedschedule",
"django_celery_beat.crontabschedule",
"django_celery_beat.intervalschedule",
"django_celery_beat.periodictask",
"django_celery_beat.solarschedule",
],
"items": [
{
"title": _("Clocked"),
"icon": "hourglass_bottom",
"link": reverse_lazy(
"admin:django_celery_beat_clockedschedule_changelist"
),
},
{
"title": _("Crontabs"),
"icon": "update",
"link": reverse_lazy(
"admin:django_celery_beat_crontabschedule_changelist"
),
},
{
"title": _("Intervals"),
"icon": "arrow_range",
"link": reverse_lazy(
"admin:django_celery_beat_intervalschedule_changelist"
),
},
{
"title": _("Periodic tasks"),
"icon": "task",
"link": reverse_lazy(
"admin:django_celery_beat_periodictask_changelist"
),
},
{
"title": _("Solar events"),
"icon": "event",
"link": reverse_lazy(
"admin:django_celery_beat_solarschedule_changelist"
),
},
],
},
]
main_settings['UNFOLD']['SIDEBAR']['navigation'] += [
{
"title": _("Celery Management"),
"icon": "add_task",
"separator": True,
"items": [
{
"title": _("Tasks Results"),
"icon": "add_task",
"link": reverse_lazy("admin:django_celery_results_taskresult_changelist"),
"permission": lambda request: request.user.has_perm('django_celery_results.view_taskresult'),
},
{
"title": _("Group Results"),
"icon": "atr",
"link": reverse_lazy("admin:django_celery_results_groupresult_changelist"),
"permission": lambda request: request.user.has_perm('django_celery_results.view_groupresult'),
},
{
"title": _("Scheduled Tasks"),
"icon": "task_alt",
"link": reverse_lazy(
"admin:django_celery_beat_clockedschedule_changelist",
),
"permission": lambda request: request.user.has_perm('django_celery_beat.view_clockedschedule'),
},
],
},
]
######################################################################
# Celery
# Docs: https://docs.celeryq.dev/en/stable/django/first-steps-with-django.html
######################################################################
main_settings.update({
'CELERY_BROKER_URL': os.environ.get('REDIS_BROKER_URL'),
'CELERY_ACCEPT_CONTENT': ['application/json'],
'CELERY_TASK_SERIALIZER': 'json',
'CELERY_RESULT_SERIALIZER': 'json',
'CELERY_TASK_TRACK_STARTED': True,
'CELERY_RESULT_BACKEND': 'django-db',
'CELERY_CACHE_BACKEND': 'django-cache',
'CELERY_RESULT_EXTENDED': True,
'CELERY_TASK_TIME_LIMIT': 60 * 60, # 1h
})
######################################################################
# Celery Beat
# Docs: https://django-celery-beat.readthedocs.io/en/latest/
######################################################################
main_settings.update({
'CELERY_BEAT_SCHEDULER': 'django_celery_beat.schedulers:DatabaseScheduler',
'DJANGO_CELERY_BEAT_TZ_AWARE': False,
})
main_settings['CACHES'] = {
'default': {
"BACKEND": "django.core.cache.backends.redis.RedisCache",
"LOCATION": os.environ.get('REDIS_BROKER_URL'),
}
}