From ec6b552268bcdb8eca7a007df5ca15544342a6f3 Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Thu, 2 Mar 2023 16:46:03 -0600 Subject: notmuch/checkmail: simplify check-mail function Simplify the check-mail function in the notmuch worker. Add account name to the logs. Signed-off-by: Tim Culverhouse Tested-by: Ben Lee-Cohen Acked-by: Robin Jarry --- worker/notmuch/worker.go | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/worker/notmuch/worker.go b/worker/notmuch/worker.go index 3b4bd5dc..3a5dc141 100644 --- a/worker/notmuch/worker.go +++ b/worker/notmuch/worker.go @@ -690,30 +690,20 @@ func (w *worker) sort(uids []uint32, func (w *worker) handleCheckMail(msg *types.CheckMail) { defer log.PanicHandler() if msg.Command == "" { - w.err(msg, fmt.Errorf("checkmail: no command specified")) + w.err(msg, fmt.Errorf("(%s) checkmail: no command specified", w.w.Name)) return } ctx, cancel := context.WithTimeout(context.Background(), msg.Timeout) defer cancel() cmd := exec.CommandContext(ctx, "sh", "-c", msg.Command) - ch := make(chan error) - go func() { - defer log.PanicHandler() - err := cmd.Run() - ch <- err - }() - select { - case <-ctx.Done(): - w.err(msg, fmt.Errorf("checkmail: timed out")) - case err := <-ch: - if err != nil { - w.err(msg, fmt.Errorf("checkmail: error running command: %w", err)) - } else { - w.w.PostMessage(&types.DirectoryInfo{ - Info: w.getDirectoryInfo(w.currentQueryName, w.query), - }, nil) - w.done(msg) - } + err := cmd.Run() + switch { + case ctx.Err() != nil: + w.err(msg, fmt.Errorf("(%s) checkmail: timed out", w.w.Name)) + case err != nil: + w.err(msg, fmt.Errorf("(%s) checkmail: error running command: %w", w.w.Name, err)) + default: + w.done(msg) } } -- cgit v1.2.3-54-g00ecf