Skip to content

Commit 1641b21

Browse files
committed
feat(slab): using slab new routes to handle async tasks
This ensures to wait for individual asynchronous tasks since there are GitHub-related operations and backend providers ones.
1 parent 973c1d2 commit 1641b21

File tree

4 files changed

+156
-90
lines changed

4 files changed

+156
-90
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
## [1.4.2](https://github.com/zama-ai/slab-github-runner/compare/v1.4.1...v1.4.2) (2025-11-28)
44

5-
65
### Bug Fixes
76

8-
* **gh:** print out any error on the runner list query ([38175e5](https://github.com/zama-ai/slab-github-runner/commit/38175e59c2c30e5cd4c7fe81d16ecfad751d0db5))
7+
- **gh:** print out any error on the runner list query
8+
([38175e5](https://github.com/zama-ai/slab-github-runner/commit/38175e59c2c30e5cd4c7fe81d16ecfad751d0db5))
99

1010
## [1.4.1](https://github.com/zama-ai/slab-github-runner/compare/v1.4.0...v1.4.1) (2024-12-20)
1111

dist/index.js

Lines changed: 77 additions & 44 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.js

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ function setOutput(label) {
77
core.setOutput('label', label)
88
}
99

10-
// This variable should only be defined for cleanup purpose.
1110
let runnerName
1211

1312
async function cleanup() {
@@ -30,28 +29,31 @@ async function start() {
3029
for (let i = 1; i <= 3; i++) {
3130
try {
3231
startInstanceResponse = await slab.startInstanceRequest()
33-
runnerName = startInstanceResponse.runner_name
3432
break
3533
} catch (error) {
3634
core.info('Retrying request now...')
3735
}
3836

3937
if (i === 3) {
4038
core.setFailed(
41-
`${provider} instance start request has failed after 3 attempts`
39+
`${provider} instance start request has failed after 3 attempts (reason: configuration fetching has failed)`
4240
)
4341
}
4442
}
4543

46-
setOutput(startInstanceResponse.runner_name)
44+
try {
45+
const waitGithubResponse = await slab.waitForGithub(
46+
startInstanceResponse.task_id,
47+
'configuration_fetching'
48+
)
4749

48-
core.info(
49-
`${provider} instance details: ${JSON.stringify(
50-
startInstanceResponse.details
51-
)}`
52-
)
50+
runnerName = waitGithubResponse.configuration_fetching.runner_name
51+
setOutput(runnerName)
52+
53+
core.info(
54+
`${provider} instance details: ${waitGithubResponse.configuration_fetching.details}`
55+
)
5356

54-
try {
5557
const waitInstanceResponse = await slab.waitForInstance(
5658
startInstanceResponse.task_id,
5759
'start'
@@ -60,10 +62,10 @@ async function start() {
6062
const instanceId = waitInstanceResponse.start.instance_id
6163
core.info(`${provider} instance started with ID: ${instanceId}`)
6264

63-
await waitForRunnerRegistered(startInstanceResponse.runner_name)
65+
await waitForRunnerRegistered(runnerName)
6466
} catch (error) {
6567
core.info(`Clean up after error, stop ${provider} instance`)
66-
await slab.stopInstanceRequest(startInstanceResponse.runner_name)
68+
await slab.stopInstanceRequest(runnerName)
6769
core.setFailed(`${provider} instance start has failed`)
6870
}
6971
}
@@ -84,6 +86,22 @@ async function stop() {
8486
}
8587
}
8688

89+
try {
90+
const waitGithubResponse = await slab.waitForGithub(
91+
stopInstanceResponse.task_id,
92+
'runner_unregister'
93+
)
94+
const taskStatus = waitGithubResponse.runner_unregister.status.toLowerCase()
95+
if (taskStatus === 'done') {
96+
core.info(
97+
`Runner ${config.input.label} unregistered from GitHub successfully`
98+
)
99+
}
100+
} catch (error) {
101+
// Unregistration failure is not critical, so we just log it and continue.
102+
core.warning('An error occurred while unregistering runner, check job logs')
103+
}
104+
87105
await slab.waitForInstance(stopInstanceResponse.task_id, 'stop')
88106

89107
core.info('Instance successfully stopped')

0 commit comments

Comments
 (0)