Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
justlorain committed Mar 31, 2024
1 parent 9abbc08 commit be8b063
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
18 changes: 10 additions & 8 deletions cron/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ var ErrReachedRetryTimes = errors.New("error reached retry times")
func Start(ctx context.Context) {
slog.Info("openalysis service started")

errC := make(chan error)
// 1. init task error
// 2. cron add func error
errC := make(chan error, 2)

slog.Info("init task starts now")
startInit := time.Now()
Expand All @@ -49,17 +51,17 @@ func Start(ctx context.Context) {
if err := InitTask(ctx, tx); err != nil {
tx.Rollback()
errC <- err
} else {
tx.Commit()
}
tx.Commit()
slog.Info("init task completed", "time", time.Since(startInit).String())

c := cron.New()
StartCron(ctx, c, errC)
defer c.Stop()

if err := util.WaitSignal(errC); err != nil {
slog.Error("receive close signal error", "signal", err.Error())
return
slog.Error("receive error signal", "err", err.Error())
}

slog.Info("openalysis service stopped")
Expand All @@ -68,15 +70,15 @@ func Start(ctx context.Context) {
func Restart(ctx context.Context) {
slog.Info("openalysis service restarted")

errC := make(chan error)
// 1. cron add func error
errC := make(chan error, 1)

c := cron.New()
StartCron(ctx, c, errC)
defer c.Stop()

if err := util.WaitSignal(errC); err != nil {
slog.Error("receive close signal error", "signal", err.Error())
return
slog.Error("receive error signal", "err", err.Error())
}

slog.Info("openalysis service stopped")
Expand Down Expand Up @@ -120,7 +122,7 @@ func StartCron(ctx context.Context, c *cron.Cron, errC chan error) {
}
slog.Info("update task completed", "time", time.Since(startUpdate).String())
}); err != nil {
slog.Error("error doing cron", "err", err)
slog.Error("error add cron func", "err", err)
errC <- err
}
c.Start()
Expand Down
22 changes: 11 additions & 11 deletions default.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
groups:
# cloudwego family
# - name: "cloudwego"
# orgs:
# - "cloudwego"
# - "kitex-contrib"
# - "hertz-contrib"
# - "volo-rs"
# repos:
# - "bytedance/sonic"
# - "bytedance/monoio"
- name: "rainiring"
- name: "cloudwego"
orgs:
- "rainiring"
- "cloudwego"
- "kitex-contrib"
- "hertz-contrib"
- "volo-rs"
repos:
- "bytedance/sonic"
- "bytedance/monoio"
# - name: "rainiring"
# orgs:
# - "rainiring"
datasource:
mysql:
host: "localhost"
Expand Down
2 changes: 1 addition & 1 deletion util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func WaitSignal(errC chan error) error {
return errors.New(sig.String())
case syscall.SIGHUP, syscall.SIGINT:
// graceful shutdown
slog.Info("receive signal: ", "signal", sig.String())
slog.Info("receive signal", "signal", sig.String())
return nil
}
case err := <-errC:
Expand Down

0 comments on commit be8b063

Please sign in to comment.