Skip to content

Commit fd26051

Browse files
committed
fix celery import
1 parent 8fc3fc3 commit fd26051

File tree

5 files changed

+23
-23
lines changed

5 files changed

+23
-23
lines changed
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# This will make sure the app is always imported when
22
# Django starts so that shared_task will use this app.
3-
from .celery import app as celery_app
3+
from django.conf import settings
44

5-
__all__ = ('celery_app',)
5+
if settings.CELERY_ALWAYS_EAGER is False:
6+
from .celery import app as celery_app
7+
__all__ = ('celery_app',)
8+
else:
9+
__all__ = ()

pythonkr_backend/pythonkr_backend/celery.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717

1818
@worker_init.connect()
1919
def init_worker(*args, **kwargs):
20-
logfire.configure(service_name="celery-worker")
20+
logfire.configure(service_name="celery-worker", send_to_logfire='if-token-present')
2121
logfire.instrument_celery()
2222

2323
@beat_init.connect()
2424
def init_beat(*args, **kwargs):
25-
logfire.configure(service_name="celery-beat")
25+
logfire.configure(service_name="celery-beat", send_to_logfire='if-token-present')
2626
logfire.instrument_celery()
2727

2828
@app.task

pythonkr_backend/pythonkr_backend/settings/base.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -187,23 +187,10 @@
187187
"0.0.0.0",
188188
]
189189

190-
# LOGGING
191-
192-
LOGGING = {
193-
"version": 1,
194-
"disable_existing_loggers": False,
195-
"handlers": {
196-
"console": {
197-
"class": "logging.StreamHandler",
198-
},
199-
},
200-
"root": {
201-
"handlers": ["console"],
202-
"level": "INFO",
203-
},
204-
}
205-
206190
# import logfire
207191
# setup logfire
208192
#logfire.configure(environment='base', service_name="web")
209-
#logfire.instrument_django()
193+
#logfire.instrument_django()
194+
195+
# testing
196+
CELERY_ALWAYS_EAGER = True

pythonkr_backend/pythonkr_backend/settings/localtesting.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,15 @@
2929
BAKERY_MULTISITE = True
3030
BUILD_DIR = os.path.join("/app/bakery_static", "build")
3131

32+
33+
# check WSGI environment
34+
IS_PRODUCTION_SERVER = os.environ.get('IS_WSGI_ENVIRONMENT', 'False') == 'True'
35+
36+
3237
# logfire settings
3338
if IS_PRODUCTION_SERVER:
3439
logfire.configure(environment='localtest')
35-
logfire.instrument_django()
40+
logfire.instrument_django()
41+
42+
# testing
43+
CELERY_ALWAYS_EAGER = True

pythonkr_backend/pythonkr_backend/settings/prod.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@
7373
CELERY_BROKER_USERNAME = os.environ.get("CELERY_USERNAME","FALSE")
7474
CELERY_BROKER_VHOST = os.environ.get("CELERY_VHOST","FALSE")
7575
# Celery Configuration Options
76+
CELERY_ALWAYS_EAGER = False
7677
CELERY_TIMEZONE = "Asia/Seoul"
7778
CELERY_TASK_TRACK_STARTED = True
78-
CELERY_BROKER_URL = "amqp://userid:password@localhost:port/virtual_host"
79+
CELERY_BROKER_URL = f"amqp://{CELERY_BROKER_USERNAME}:{CELERY_BROKER_PASSWORD}@localhost:5672/{CELERY_BROKER_VHOST}"
7980
CELERY_TASK_TIME_LIMIT = 30 * 60

0 commit comments

Comments
 (0)