Skip to content

Commit

Permalink
fix watcher closure
Browse files Browse the repository at this point in the history
  • Loading branch information
sonroyaalmerol committed Nov 18, 2024
1 parent dd7f87f commit 7c2e9f4
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions internal/store/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ func (storeInstance *Store) GetMostRecentTask(ctx context.Context, job *Job) (ch
if err != nil {
return nil, fmt.Errorf("failed to create watcher: %w", err)
}
defer watcher.Close()

err = watcher.Add(tasksParentPath)
if err != nil {
Expand All @@ -115,6 +114,7 @@ func (storeInstance *Store) GetMostRecentTask(ctx context.Context, job *Job) (ch
returnChan := make(chan Task)

go func() {
defer watcher.Close()
defer close(returnChan)
for {
select {
Expand All @@ -127,6 +127,7 @@ func (storeInstance *Store) GetMostRecentTask(ctx context.Context, job *Job) (ch
}
} else {
searchString := fmt.Sprintf(":backup:%s%shost-%s", job.Store, encodeToHexEscapes(":"), encodeToHexEscapes(backupId))
log.Printf("Checking %s == %s\n", event.Name, searchString)
if strings.Contains(event.Name, searchString) {
newTask, err := storeInstance.GetTaskByUPID(event.Name)
if err != nil {
Expand All @@ -137,9 +138,7 @@ func (storeInstance *Store) GetMostRecentTask(ctx context.Context, job *Job) (ch
}
}
}
case err := <-watcher.Errors:
log.Println("Watcher error:", err)
case <-time.After(time.Second * 120):
case <-time.After(time.Second * 60):
log.Println("GetMostRecentTask: error getting tasks: timeout, not found")
return
case <-ctx.Done():
Expand Down

0 comments on commit 7c2e9f4

Please sign in to comment.