Skip to content

Commit 35db5f7

Browse files
committed
queue setting
1 parent 14b29d0 commit 35db5f7

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

.env.example

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,16 @@ VERIFY_SSL=true
77

88
# Queue configuration
99
MAX_QUEUE_SIZE=100
10-
RATE_LIMIT_REQUESTS=30
11-
RATE_LIMIT_WINDOW=60
10+
11+
# Celery Worker Configuration
12+
# CELERY_CONCURRENCY=4 # Used in Docker startup command, not directly by Python
13+
CELERY_TASK_TIME_LIMIT=300 # Max time in seconds for a task to run (default: 300)
14+
CELERY_WORKER_PREFETCH_MULTIPLIER=5 # How many tasks a worker fetches ahead (default: 5)
15+
CELERY_WORKER_MAX_TASKS_PER_CHILD=1000 # Tasks per worker process before restart (default: 1000)
16+
17+
# Celery Broker/Backend (Redis example)
18+
# CELERY_BROKER_URL=redis://localhost:6379/0
19+
# CELERY_RESULT_BACKEND=redis://localhost:6379/0
1220

1321
# Flask configuration
1422
FLASK_ENV=production

celery_worker.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@
3535
timezone='UTC',
3636
enable_utc=True,
3737
task_track_started=True,
38-
task_time_limit=300, # 5 minutes max
39-
worker_prefetch_multiplier=1, # Process one task at a time
40-
worker_max_tasks_per_child=1000, # Restart worker after 1000 tasks
38+
# Read settings from environment variables with defaults
39+
task_time_limit=int(os.getenv('CELERY_TASK_TIME_LIMIT', '300')), # 5 minutes max
40+
worker_prefetch_multiplier=int(os.getenv('CELERY_WORKER_PREFETCH_MULTIPLIER', '1')), # Process one task at a time
41+
worker_max_tasks_per_child=int(os.getenv('CELERY_WORKER_MAX_TASKS_PER_CHILD', '1000')), # Restart worker after 1000 tasks
4142
)
4243

4344
def _get_headers():

0 commit comments

Comments
 (0)