Files
insights/bin/docker-worker-celery
zeekayandGitHub eeb8af756c restore served Django monolith + publish to ghcr for insights.hanzo.ai deploy (#60)
Reverses the 175eace7b django retirement per CTO tonight-deploy directive.

Entrypoints (restored from pre-175eace7b working versions; the debrand #59
only touched the retirement-notice strings, which are deleted on restore):
- manage.py            real Django execute_from_command_line (+ common/ path)
- bin/docker           migrate -> worker -> server
- bin/docker-server    dual-mode Granian/Unit wrapper
- bin/docker-worker    migrate-check + node + celery
- bin/docker-worker-celery  full celery worker launcher
(bin/docker-migrate was never neutered; already runs manage.py migrate.)

CI: restore .github/workflows/container-images-cd.yml (deleted in 657c5fbcef)
so main/v* builds push the monolith Dockerfile to ghcr.io/hanzoai/insights
(:{{version}} on v-tag + :sha-<sha>) on the self-hosted hanzo-build-linux-amd64
ARC pool. amd64-only: the DOKS arm64 ARC pool is offline (no DO arm64 droplets)
and the deploy pins kubernetes.io/arch: amd64; arm64 leg is documented for
re-enable. The ECR PR-cache path (container-images-ci.yml) is left untouched.

Verified: served path has no other retire stubs (settings/urls/api clean);
redis path is real (redis.from_url + django-redis + celery on REDIS_URL, no
SQLite/Base adapter despite #52's title); collectstatic is IS_COLLECT_STATIC-
guarded; manage.py py_compiles; all bin/docker* pass bash -n.

Gated: do NOT deploy. Restore insights-web/worker Service CRs in universe.
2026-07-10 11:03:11 -07:00

97 lines
2.8 KiB
Bash
Executable File

#!/bin/bash
set -e
help () {
echo "$0 - start Insights's Celery worker"
echo
echo "$0 [options]"
echo
echo "Options:"
echo " --help, -h show this brief help"
echo " --with-scheduler start RedBeat, the Celery scheduler (deprecates --with-beat)"
echo " --concurrency=<N> start N workers (overrides env var WEB_CONCURRENCY)"
echo
echo "Advanced Celery options (disabled by default):"
echo " --with-heartbeat start Celery internal heartbeat (normally not useful)"
echo " --with-mingle start Celery mingle (normally not useful)"
exit 0
}
with_scheduler=false
with_gossip=true
with_heartbeat=false
with_mingle=false
while test $# -gt 0; do
case "$1" in
-h|--help)
help
;;
--with-scheduler)
with_scheduler=true
shift
;;
--with-beat) # Deprecated since the name is too similar to "heartbeat"
echo "⚠️ Using docker-worker-celery with --with-beat. This argument is deprecated. Use --with-scheduler instead!"
with_scheduler=true
shift
;;
--with-heartbeat)
with_heartbeat=true
shift
;;
--with-mingle)
with_mingle=true
shift
;;
--concurrency*)
export WEB_CONCURRENCY=`echo $1 | sed -e 's/^[^=]*=//g'`
shift
;;
*)
break
;;
esac
done
# Stop any background jobs on exit
trap 'kill $(jobs -p)' EXIT
if [ "$with_scheduler" == "true" ]; then
./bin/docker-worker-beat &
fi
FLAGS=()
FLAGS+=("-Ofair")
FLAGS+=("-n node@%h")
[ "$with_gossip" == "false" ] && FLAGS+=("--without-gossip")
[ "$with_mingle" == "false" ] && FLAGS+=("--without-mingle")
[ "$with_heartbeat" == "false" ] && FLAGS+=("--without-heartbeat")
# On Heroku $WEB_CONCURRENCY contains suggested number of forks per dyno type
# https://github.com/heroku/heroku-buildpack-python/blob/main/vendor/WEB_CONCURRENCY.sh
[[ -n "${WEB_CONCURRENCY}" ]] && FLAGS+=" --concurrency $WEB_CONCURRENCY"
# Restart worker process after it processes this many tasks (to mitigate memory leaks)
[[ -n "${CELERY_MAX_TASKS_PER_CHILD}" ]] && FLAGS+=" --max-tasks-per-child $CELERY_MAX_TASKS_PER_CHILD"
# Restart worker process after it exceeds this much memory usage (to mitigate memory leaks)
[[ -n "${CELERY_MAX_MEMORY_PER_CHILD}" ]] && FLAGS+=" --max-memory-per-child $CELERY_MAX_MEMORY_PER_CHILD"
[[ -n "${CELERY_WORKER_PREFETCH_MULTIPLIER}" ]] && FLAGS+=" --prefetch-multiplier $CELERY_WORKER_PREFETCH_MULTIPLIER"
if [[ -z "${CELERY_WORKER_QUEUES}" ]]; then
source ./bin/celery-queues.env
fi
echo
echo "SKIP_ASYNC_MIGRATIONS_SETUP=0 celery -A insights worker ${FLAGS[*]}"
echo
./bin/migrate-check
SKIP_ASYNC_MIGRATIONS_SETUP=0 CELERY_WORKER_QUEUES=$CELERY_WORKER_QUEUES celery -A insights worker ${FLAGS[*]} &
# Exit if any processes exit, and exit with it's exit code
wait -n
exit $?