mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2026-10-24 16:59:19 +03:00
Move `Suicide` into `common`, add a new global for tracking pending exit code, and exit with that code when finishing the `main()` func. As I don't have a known reproduction for a fatal error, I performed a manual end-to-end test by dropping a fatal error into the cache startup routine and verifying that the exit code was `1`. Fixes #1219, partially. <!--start release-notes-assistant--> <!--URL:https://code.forgejo.org/forgejo/runner--> - bug fixes - [PR](https://code.forgejo.org/forgejo/runner/pulls/1222): <!--number 1222 --><!--line 0 --><!--description Zml4OiB1bnJlY292ZXJhYmxlIGVycm9ycyBpbiBhcnRpZmFjdGNhY2hlIHNob3VsZCBoYXZlIG5vbi16ZXJvIGV4aXQgY29kZQ==-->fix: unrecoverable errors in artifactcache should have non-zero exit code<!--description--> <!--end release-notes-assistant--> Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/1222 Reviewed-by: earl-warren <earl-warren@noreply.code.forgejo.org> Co-authored-by: Mathieu Fenniak <mathieu@fenniak.net> Co-committed-by: Mathieu Fenniak <mathieu@fenniak.net>
28 lines
594 B
Go
28 lines
594 B
Go
package common
|
|
|
|
import (
|
|
"os"
|
|
)
|
|
|
|
type RunnerExitCode int
|
|
|
|
const (
|
|
Success RunnerExitCode = iota
|
|
CacheUnrecoverableError
|
|
)
|
|
|
|
var PendingExitCode RunnerExitCode
|
|
|
|
// When the program exits, store an exit code to be used at that time. If `SetPendingExitCode` is called multiple times
|
|
// only the first invocation will be saved.
|
|
func SetPendingExitCode(exitCode RunnerExitCode) {
|
|
if PendingExitCode == 0 {
|
|
PendingExitCode = exitCode
|
|
}
|
|
}
|
|
|
|
// Exit with an exit code that was previously set in `SetPendingExitCode`, or success if it was never set.
|
|
func Exit() {
|
|
os.Exit(int(PendingExitCode))
|
|
}
|