0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-24 00:47:50 +01:00

chore(dev): clean up background jobs on EXIT and prop. exit code (#10916)

We were for instance calling trap at a point where it wouldn't get
called, and giving special status to some processes to run in the
foreground.

Instead we:

 1. wait for any process exit
 2. use it's exit code for the calling process
 3. kill background processes on EXIT
This commit is contained in:
Harry Waye 2022-07-21 14:32:38 +01:00 committed by GitHub
parent 1cb2e3224a
commit 40616f0d7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 5 deletions

View File

@ -3,5 +3,12 @@ set -e
./bin/migrate-check ./bin/migrate-check
# Stop any background jobs on exit
trap 'kill $(jobs -p)' EXIT
./bin/plugin-server & ./bin/plugin-server &
./bin/docker-worker-celery --with-scheduler ./bin/docker-worker-celery --with-scheduler &
# Exit if any processes exit, and exit with it's exit code
wait -n
exit $?

View File

@ -59,6 +59,9 @@ while test $# -gt 0; do
esac esac
done done
# Stop any background jobs on exit
trap 'kill $(jobs -p)' EXIT
if [ "$with_scheduler" == "true" ]; then if [ "$with_scheduler" == "true" ]; then
./bin/docker-worker-beat & ./bin/docker-worker-beat &
fi fi
@ -80,7 +83,9 @@ echo
./bin/migrate-check ./bin/migrate-check
SKIP_ASYNC_MIGRATIONS_SETUP=0 celery -A posthog worker ${FLAGS[*]} SKIP_ASYNC_MIGRATIONS_SETUP=0 celery -A posthog worker ${FLAGS[*]} &
# Exit if any processes exit, and exit with it's exit code
wait -n
exit $?
# Stop the beat!
trap 'kill $(jobs -p)' EXIT

View File

@ -44,7 +44,7 @@ fi
if [[ -n $NO_RESTART_LOOP ]]; then if [[ -n $NO_RESTART_LOOP ]]; then
echo "▶️ Starting plugin server..." echo "▶️ Starting plugin server..."
trap 'kill -TERM $child 2>/dev/null; while kill -0 $child 2>/dev/null; do sleep 1; done' SIGTERM trap 'kill -TERM $child 2>/dev/null; while kill -0 $child 2>/dev/null; do sleep 1; done' EXIT
yarn $cmd & yarn $cmd &
child=$! child=$!
wait $child wait $child