Skip to content

Commit

Permalink
fix: add sleep before canceling to handle interrupt signals
Browse files Browse the repository at this point in the history
  • Loading branch information
revelaction committed Sep 19, 2024
1 parent 82814a0 commit 71d1148
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions cmd/ical-git/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ func tick(ctx context.Context, cancel context.CancelFunc, conf config.Config, sc

err := run(conf, sc)
if err != nil {
// sleep before canceling here, to allow interrupt signals to still work
time.Sleep(time.Minute)
cancel()
slog.Error("Tick Error, canceling", "error", err)
return
Expand All @@ -188,6 +190,8 @@ func tick(ctx context.Context, cancel context.CancelFunc, conf config.Config, sc
err = run(conf, sc)
slog.Info("🔧 ending tick work")
if err != nil {
// sleep before canceling here, to allow interrupt signals to still work
time.Sleep(time.Minute)
cancel()
slog.Error("Tick Error, canceling", "error", err)
return
Expand All @@ -205,10 +209,10 @@ func run(conf config.Config, sc *schedule.Scheduler) error {

var f fetch.Fetcher
if conf.IsFetcherGit() {
slog.Info("🧲 Fetch: git")
slog.Info("🧲 Fetch: git")
f = git.New(conf.FetcherGit.Url, conf.FetcherGit.PrivateKeyPath)
} else {
slog.Info("🧲 Fetch: filesystem")
slog.Info("🧲 Fetch: filesystem")
f = filesystem.New(conf.FetcherFilesystem.Directory)
}

Expand All @@ -217,12 +221,12 @@ func run(conf config.Config, sc *schedule.Scheduler) error {
p := ical.NewParser(conf, tickStart)
for f := range ch {
if f.Error != nil {
slog.Error("🧲 Fetch:", "🚨 Error:", f.Error)
slog.Error("🧲 Fetch:", "🚨 Error:", f.Error)
return fmt.Errorf("error: %w", f.Error)
}
err := p.Parse(f)
if err != nil {
slog.Info("👀 Parse: error. Skipping", "error", err)
slog.Info("👀 Parse: error. Skipping", "error", err)
}
}

Expand Down

0 comments on commit 71d1148

Please sign in to comment.