mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2024-12-01 21:23:43 +03:00
34 lines
532 B
Go
34 lines
532 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
|
|
"codeberg.org/forgejo/runner/cmd"
|
|
)
|
|
|
|
func withContextFunc(ctx context.Context, f func()) context.Context {
|
|
ctx, cancel := context.WithCancel(ctx)
|
|
go func() {
|
|
c := make(chan os.Signal, 1)
|
|
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
|
|
defer signal.Stop(c)
|
|
|
|
select {
|
|
case <-ctx.Done():
|
|
case <-c:
|
|
cancel()
|
|
f()
|
|
}
|
|
}()
|
|
|
|
return ctx
|
|
}
|
|
|
|
func main() {
|
|
ctx := withContextFunc(context.Background(), func() {})
|
|
// run the command
|
|
cmd.Execute(ctx)
|
|
}
|