1
0
mirror of https://gitea.com/gitea/act_runner synced 2024-11-13 18:25:50 +01:00
act_runner/main.go

35 lines
531 B
Go
Raw Normal View History

2022-04-27 11:45:53 +02:00
package main
import (
"context"
"os"
"os/signal"
"syscall"
2022-04-27 11:45:53 +02:00
"gitea.com/gitea/act_runner/cmd"
)
func withContextFunc(ctx context.Context, f func()) context.Context {
2022-04-27 11:45:53 +02:00
ctx, cancel := context.WithCancel(ctx)
go func() {
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
defer signal.Stop(c)
2022-04-27 11:45:53 +02:00
select {
case <-ctx.Done():
2022-04-27 11:45:53 +02:00
case <-c:
cancel()
f()
2022-04-27 11:45:53 +02:00
}
}()
return ctx
}
func main() {
ctx := withContextFunc(context.Background(), func() {})
2022-04-27 11:45:53 +02:00
// run the command
cmd.Execute(ctx)
}