feat: allow graceful shutdowns (#546)

Add a `Shutdown(context.Context) error` method to the Poller. Calling this method will first shutdown all active polling, preventing any new jobs from spawning. It will then wait for either all jobs to finish, or for the context to be cancelled. If the context is cancelled, it will then force all jobs to end, and then exit.

Fixes https://gitea.com/gitea/act_runner/issues/107

Co-authored-by: Rowan Bohde <rowan.bohde@gmail.com>
Reviewed-on: https://gitea.com/gitea/act_runner/pulls/546
Reviewed-by: Jason Song <i@wolfogre.com>
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: rowan-allspice <rowan-allspice@noreply.gitea.com>
Co-committed-by: rowan-allspice <rowan-allspice@noreply.gitea.com>
(cherry picked from commit d1d3cad4b0bfd0bfc5df344306f304043ff63223)

Conflicts:
	internal/pkg/config/config.example.yaml
	internal/pkg/config/config.go
	scripts/run.sh
	trivial context conflicts
This commit is contained in:
rowan-allspice 2024-05-27 07:38:55 +00:00 committed by Earl Warren
parent 1b95689795
commit 30029567f7
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
6 changed files with 90 additions and 20 deletions

View file

@ -45,4 +45,4 @@ fi
# Prevent reading the token from the forgejo-runner process
unset GITEA_RUNNER_REGISTRATION_TOKEN
forgejo-runner daemon ${CONFIG_ARG}
exec forgejo-runner daemon ${CONFIG_ARG}