Skip to content

Commit

Permalink
build(core): swap in stoppable trigger runner script
Browse files Browse the repository at this point in the history
  • Loading branch information
vindard committed Dec 19, 2023
1 parent 968f72d commit 158ef9c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
5 changes: 5 additions & 0 deletions dev/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,8 @@ sh_binary(
name = "setup-hydra-client",
main = "bin/setup-hydra-client.sh",
)

sh_binary(
name = "stoppable-trigger",
main = "bin/run-stoppable-trigger.sh",
)
2 changes: 1 addition & 1 deletion dev/Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ local_resource(
"api-trigger",
labels = ["core"],
cmd = "buck2 build {}".format(api_trigger_target),
serve_cmd = "buck2 run {}".format(api_trigger_target),
serve_cmd = "buck2 run //dev:stoppable-trigger {}".format(api_trigger_target),
serve_env = core_serve_env,
allow_parallel = True,
readiness_probe = probe(
Expand Down
44 changes: 44 additions & 0 deletions dev/bin/run-stoppable-trigger.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

buck_target="$1"

REPO_ROOT=$(git rev-parse --show-toplevel)
BATS_DIR="${REPO_ROOT}/bats"

TRIGGER_PID_FILE="$BATS_DIR/.trigger_pid"

CONTROL_FILE="$BATS_DIR/.stop_trigger"
rm "$CONTROL_FILE"

start_trigger() {
buck2 run "$buck_target" &
echo "$!" > "$TRIGGER_PID_FILE"
}

trigger_is_running() {
SERVER_PID=$(head -n 1 "$TRIGGER_PID_FILE")
if ps -p "$SERVER_PID" > /dev/null; then
return 0
fi
return 1
}

while true; do
if [[ -f "$CONTROL_FILE" ]]; then
if trigger_is_running > /dev/null; then
echo "Stopping server..."
kill -15 $SERVER_PID
if [[ "$?" == "0" ]]; then
echo "Successfully stopped trigger"
else
echo "Could not stop trigger, exiting..."
exit 1
fi
fi
else
if ! trigger_is_running > /dev/null; then
start_trigger
fi
fi
sleep 2
done

0 comments on commit 158ef9c

Please sign in to comment.