Skip to content

Commit 17d04f0

Browse files
authored
Merge pull request #28 from darjeeling/trans_article
Trans article
2 parents 356fc3b + fd26051 commit 17d04f0

File tree

7 files changed

+201
-22
lines changed

7 files changed

+201
-22
lines changed

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@ readme = "README.md"
66
requires-python = ">=3.12"
77
dependencies = [
88
"beautifulsoup4>=4.13.3",
9+
"celery>=5.5.2",
910
"django>=5.1.7",
1011
"django-tailwind[reload]>=3.8.0",
1112
"gunicorn>=23.0.0",
1213
"httpx>=0.28.1",
1314
"llm>=0.24.2",
1415
"llm-gemini>=0.18.1",
15-
"logfire[django,psycopg,system-metrics]>=3.16.0",
16+
"logfire[celery,django,psycopg,system-metrics]>=3.16.0",
1617
"lxml>=5.3.2",
1718
"markdown>=3.7",
1819
"psycopg[binary]>=3.2.5",
20+
"pydantic-ai-slim[anthropic,openai]>=0.2.6",
1921
"pydantic-ai[logfire]>=0.2.6",
2022
"readtime>=3.0.0",
2123
"requests>=2.32.3",
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# This will make sure the app is always imported when
2+
# Django starts so that shared_task will use this app.
3+
from django.conf import settings
4+
5+
if settings.CELERY_ALWAYS_EAGER is False:
6+
from .celery import app as celery_app
7+
__all__ = ('celery_app',)
8+
else:
9+
__all__ = ()
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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", send_to_logfire='if-token-present')
21+
logfire.instrument_celery()
22+
23+
@beat_init.connect()
24+
def init_beat(*args, **kwargs):
25+
logfire.configure(service_name="celery-beat", send_to_logfire='if-token-present')
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+
}

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: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,15 @@
6666
logfire.configure(environment='prod', service_name="web", service_version=sha_service_version)
6767
logfire.instrument_django()
6868
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_ALWAYS_EAGER = False
77+
CELERY_TIMEZONE = "Asia/Seoul"
78+
CELERY_TASK_TRACK_STARTED = True
79+
CELERY_BROKER_URL = f"amqp://{CELERY_BROKER_USERNAME}:{CELERY_BROKER_PASSWORD}@localhost:5672/{CELERY_BROKER_VHOST}"
80+
CELERY_TASK_TIME_LIMIT = 30 * 60

uv.lock

Lines changed: 123 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)