Skip to content

Commit fa3eb52

Browse files
committed
update(parallel_tests): add an example of handling signals for Spot Instances
1 parent f608dee commit fa3eb52

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

docusaurus/docs/ruby/parallel_tests.mdx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,24 @@ Create `bin/parallel_tests` and make it executable `chmod u+x`:
8181
```
8282
</TabItem>
8383
<TabItem value="parallel_tests-on-parallel-nodes-spot-instances" label="with Spot Instances">
84+
If you use AWS Spot Instances as CI nodes, ensure that the termination signal is properly propagated down the script hierarchy.
85+
8486
```bash
8587
#!/bin/bash
8688

89+
handle_signal() {
90+
local signal=$1
91+
if [[ -n $knapsack_pro_pid ]]; then
92+
echo "KNAPSACK_PRO_CI_NODE_INDEX=$KNAPSACK_PRO_CI_NODE_INDEX Received signal $signal in bin/parallel_tests, terminating the Knapsack Pro process with TERM"
93+
kill -TERM $knapsack_pro_pid
94+
echo "KNAPSACK_PRO_CI_NODE_INDEX=$KNAPSACK_PRO_CI_NODE_INDEX Waiting for the Knapsack Pro process with PID $knapsack_pro_pid to terminate"
95+
wait $knapsack_pro_pid
96+
fi
97+
}
98+
99+
trap 'handle_signal TERM' TERM
100+
trap 'handle_signal INT' INT
101+
87102
# The Knapsack Pro API sees 3 * 2 = 6 parallel nodes
88103
export KNAPSACK_PRO_CI_NODE_TOTAL=$(( $PARALLEL_TESTS_CONCURRENCY * $KNAPSACK_PRO_CI_NODE_TOTAL ))
89104

@@ -99,7 +114,9 @@ Create `bin/parallel_tests` and make it executable `chmod u+x`:
99114
# Debug log
100115
echo KNAPSACK_PRO_CI_NODE_TOTAL=$KNAPSACK_PRO_CI_NODE_TOTAL KNAPSACK_PRO_CI_NODE_INDEX=$KNAPSACK_PRO_CI_NODE_INDEX PARALLEL_TESTS_CONCURRENCY=$PARALLEL_TESTS_CONCURRENCY
101116

102-
bundle exec rake knapsack_pro:queue:rspec
117+
bundle exec rake knapsack_pro:queue:rspec &
118+
knapsack_pro_pid=$!
119+
wait $knapsack_pro_pid
103120
```
104121
</TabItem>
105122
</Tabs>

0 commit comments

Comments
 (0)