Compare commits

..

1 Commits
dev ... master

Author SHA1 Message Date
loveuer
4257cd3668 refactor: project code arch; feat: cancel operation anytime 2025-02-08 11:42:56 +08:00
3 changed files with 7 additions and 7 deletions

View File

@ -62,11 +62,6 @@ func run(cmd *cobra.Command, args []string) error {
return err return err
} }
go func() {
<-cmd.Context().Done()
log.Fatal(cmd.Context().Err().Error())
}()
switch opt.Cfg.Args.Type { switch opt.Cfg.Args.Type {
case "data": case "data":
return core.RunData(cmd, input, output) return core.RunData(cmd, input, output)

View File

@ -72,7 +72,7 @@ func RunData(cmd *cobra.Command, input, output model.IO[map[string]any]) error {
return return
} }
log.Info("Dump: dump data success = %d", wroteCount) log.Info("Dump: dump data success = %d total = %d", wroteCount, total)
} }
} }
}() }()
@ -119,7 +119,7 @@ func RunData(cmd *cobra.Command, input, output model.IO[map[string]any]) error {
wc.Wait() wc.Wait()
log.Info("Dump: dump data success, total = %d", total) log.Info("Dump: dump all data success, total = %d", total)
return nil return nil
} }

View File

@ -14,6 +14,11 @@ func main() {
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT) ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
defer cancel() defer cancel()
go func() {
<-ctx.Done()
log.Fatal(ctx.Err().Error())
}()
if err := cmd.Run(ctx); err != nil { if err := cmd.Run(ctx); err != nil {
log.Error(err.Error()) log.Error(err.Error())
return return