File tree Expand file tree Collapse file tree 3 files changed +57
-1
lines changed
pythonkr_backend/pythonkr_backend Expand file tree Collapse file tree 3 files changed +57
-1
lines changed Original file line number Diff line number Diff line change
1
+ # This will make sure the app is always imported when
2
+ # Django starts so that shared_task will use this app.
3
+ from .celery import app as celery_app
4
+
5
+ __all__ = ('celery_app' ,)
Original file line number Diff line number Diff line change
1
+ import logfire
2
+ from celery import Celery
3
+ from celery .signals import worker_init , beat_init
4
+
5
+ app = Celery ('proj' )
6
+
7
+
8
+ # Using a string here means the worker doesn't have to serialize
9
+ # the configuration object to child processes.
10
+ # - namespace='CELERY' means all celery-related configuration keys
11
+ # should have a `CELERY_` prefix.
12
+ app .config_from_object ('django.conf:settings' , namespace = 'CELERY' )
13
+
14
+ # Load task modules from all registered Django apps.
15
+ app .autodiscover_tasks ()
16
+
17
+
18
+ @worker_init .connect ()
19
+ def init_worker (* args , ** kwargs ):
20
+ logfire .configure (service_name = "celery-worker" )
21
+ logfire .instrument_celery ()
22
+
23
+ @beat_init .connect ()
24
+ def init_beat (* args , ** kwargs ):
25
+ logfire .configure (service_name = "celery-beat" )
26
+ logfire .instrument_celery ()
27
+
28
+ @app .task
29
+ def add (x : int , y : int ):
30
+ return x + y
31
+
32
+ add .delay (42 , 50 )
33
+
34
+
35
+ app .conf .beat_schedule = {
36
+ "add-every-30-seconds" : {
37
+ "task" : "tasks.add" ,
38
+ "schedule" : 30.0 ,
39
+ "args" : (16 , 16 ),
40
+ },
41
+ }
Original file line number Diff line number Diff line change 66
66
logfire .configure (environment = 'prod' , service_name = "web" , service_version = sha_service_version )
67
67
logfire .instrument_django ()
68
68
logfire .instrument_system_metrics ()
69
- #logfire.instrument_psycopg('psycopg')
69
+ #logfire.instrument_psycopg('psycopg')
70
+
71
+ # celery
72
+ CELERY_BROKER_PASSWORD = os .environ .get ("CELERY_PASSWORD" ,"FALSE" )
73
+ CELERY_BROKER_USERNAME = os .environ .get ("CELERY_USERNAME" ,"FALSE" )
74
+ CELERY_BROKER_VHOST = os .environ .get ("CELERY_VHOST" ,"FALSE" )
75
+ # Celery Configuration Options
76
+ CELERY_TIMEZONE = "Asia/Seoul"
77
+ CELERY_TASK_TRACK_STARTED = True
78
+ CELERY_BROKER_URL = "amqp://userid:password@localhost:port/virtual_host"
79
+ CELERY_TASK_TIME_LIMIT = 30 * 60
You can’t perform that action at this time.
0 commit comments