| package app |
|
|
| import ( |
| "context" |
| "kpl/internal/conf" |
| "kpl/pkg/logx" |
| "kpl/pkg/tools" |
| "os" |
| "time" |
| ) |
|
|
| func Run(ctx context.Context) { |
| cleanUp := tools.Stack{} |
| ctx = logx.TagContext(ctx, "initial") |
| logx.Init(ctx) |
|
|
| |
| conf.Init(ctx) |
|
|
| |
| cleanUp.Push(Start(ctx)) |
|
|
| |
| for i, url := range conf.CONF.HgUrls { |
| logx.WithContext(ctx).Info("HG_URL", i, ": ", url) |
| } |
|
|
| for i, serv00 := range conf.CONF.Serv00s { |
| logx.WithContext(ctx).Info("Serv00", i, ": ", serv00.Username, "@", serv00.Host, ":", serv00.Port) |
| } |
|
|
| AsyncTimingTask(time.Duration(conf.CONF.HgIntervalSec)*time.Second, func() { |
| for _, url := range conf.CONF.HgUrls { |
| go DoGetRequest(ctx, url, conf.CONF.Proxy) |
| } |
| }) |
|
|
| AsyncTimingTask(time.Duration(conf.CONF.Serv00IntervalSec)*time.Second, func() { |
| for _, serv00 := range conf.CONF.Serv00s { |
| go KplServ00(ctx, serv00.Username, serv00.Password, serv00.Host, serv00.Port, serv00.Cmd) |
| } |
| }) |
|
|
| |
| { |
| exitCode := 1 |
| exitCode = tools.HandleSignals(exitCode) |
| ctx = logx.TagContext(ctx, "cleanup") |
| for cleanUp.Next() { |
| cleanUp.Pop()(ctx) |
| } |
| time.Sleep(time.Second) |
| os.Exit(exitCode) |
| } |
| } |
|
|