@@ -8,26 +8,52 @@ CELERY__STATE_DB=${CELERY__STATE_DB:-"/mnt/volumes/statics/worker@%h.state"}
88CELERY__MAX_MEMORY_PER_CHILD=${CELERY__MAX_MEMORY_PER_CHILD:- " 200000" }
99CELERY__AUTOSCALE_VALUES=${CELERY__AUTOSCALE_VALUES:- " 10,5" }
1010CELERY__MAX_TASKS_PER_CHILD=${CELERY__MAX_TASKS_PER_CHILD:- " 10" }
11- CELERY__OPTS=${CELERY__OPTS:- " --without-gossip --without-mingle -Ofair -B -E" }
12- CELERY__BEAT_SCHEDULE=${CELERY__BEAT_SCHEDULE:- " celery.beat:PersistentScheduler" }
11+ CELERY__OPTS=${CELERY__OPTS:- " --without-gossip --without-mingle -Ofair -E" }
1312CELERY__LOG_LEVEL=${CELERY__LOG_LEVEL:- " ERROR" }
1413CELERY__LOG_FILE=${CELERY__LOG_FILE:- " /var/log/celery.log" }
1514CELERY__WORKER_NAME=${CELERY__WORKER_NAME:- " worker1@%h" }
1615CELERY__WORKER_CONCURRENCY=${CELERY__WORKER_CONCURRENCY:- " 4" }
1716
17+ # Celery beat settings
18+ CELERY__BEAT_SCHEDULE=${CELERY__BEAT_SCHEDULE:- " celery.beat:PersistentScheduler" }
19+ CELERY__BEAT_LOG=${CELERY__BEAT_LOG:- " /var/log/celery_beat.log" }
20+
1821# Harvester settings
1922CELERY__HARVESTER_WORKER_NAME=${CELERY__HARVESTER_WORKER_NAME:- " harvesting_worker@%h" }
2023CELERY__HARVESTER_CONCURRENCY=${CELERY__HARVESTER_CONCURRENCY:- " 10" }
2124CELERY__HARVESTER_AUTOSCALE_VALUES=${CELERY__HARVESTER_AUTOSCALE_VALUES:- " 15,10" }
2225CELERY__HARVESTER_MAX_MEMORY_PER_CHILD=${CELERY__MAX_MEMORY_PER_CHILD:- " 500000" }
2326
27+ # --- FIX: Remove stale Beat pidfile before starting beat ---
28+ BEAT_PIDFILE=" /tmp/celerybeat.pid"
29+
30+ if [ -f " $BEAT_PIDFILE " ]; then
31+ PID=$( cat " $BEAT_PIDFILE " 2> /dev/null)
32+
33+ # If PID exists and is running → warn but continue (avoid killing)
34+ if kill -0 " $PID " 2> /dev/null; then
35+ echo " WARNING: Celery Beat seems to be running already (PID $PID ). Removing stale pidfile anyway."
36+ else
37+ echo " Removing stale Celery Beat pidfile: $BEAT_PIDFILE "
38+ fi
39+
40+ rm -f " $BEAT_PIDFILE "
41+ fi
42+ # --- END FIX ---
43+
44+ echo " Starting Celery Beat..."
45+ $CELERY_BIN -A $CELERY_APP beat --scheduler=$CELERY__BEAT_SCHEDULE \
46+ --loglevel=$CELERY__LOG_LEVEL -f $CELERY__BEAT_LOG --pidfile=/tmp/celerybeat.pid &
47+
48+ echo " Starting Default Celery Worker..."
2449$CELERY_BIN -A $CELERY_APP worker --autoscale=$CELERY__AUTOSCALE_VALUES \
2550 --max-memory-per-child=$CELERY__MAX_MEMORY_PER_CHILD $CELERY__OPTS \
26- --statedb=$CELERY__STATE_DB --scheduler= $CELERY__BEAT_SCHEDULE \
51+ --statedb=$CELERY__STATE_DB \
2752 --loglevel=$CELERY__LOG_LEVEL -n $CELERY__WORKER_NAME -f $CELERY__LOG_FILE \
2853 --concurrency=$CELERY__WORKER_CONCURRENCY --max-tasks-per-child=$CELERY__MAX_TASKS_PER_CHILD \
2954 -X harvesting &
3055
56+ echo " Starting Harvester Celery Worker..."
3157$CELERY_BIN -A $CELERY_APP worker -Q harvesting \
3258 --autoscale=$CELERY__HARVESTER_AUTOSCALE_VALUES \
3359 --max-memory-per-child=$CELERY__HARVESTER_MAX_MEMORY_PER_CHILD \
@@ -36,5 +62,9 @@ $CELERY_BIN -A $CELERY_APP worker -Q harvesting \
3662 --concurrency=$CELERY__HARVESTER_CONCURRENCY \
3763 -f $CELERY__LOG_FILE &
3864
39- # Keep the container alive
40- wait
65+ # Wait for any process to exit
66+ wait -n
67+
68+ # Exit with the status of the process that exited first
69+ # Docker will restart the container if this is non-zero (i.e., a failure)
70+ exit $?
0 commit comments