diff options
author | Tim Culverhouse <tim@timculverhouse.com> | 2023-03-02 16:46:03 -0600 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-03-07 16:37:02 +0100 |
commit | ec6b552268bcdb8eca7a007df5ca15544342a6f3 (patch) | |
tree | 2c8a48bec5032a545ad98ad09f842922b44b1c1b /worker/notmuch | |
parent | 27cacdfca581d1f51f3e99a8f94c859fe8576790 (diff) | |
download | aerc-ec6b552268bcdb8eca7a007df5ca15544342a6f3.tar.gz |
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 <tim@timculverhouse.com>
Tested-by: Ben Lee-Cohen <ben@lee-cohen.com>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'worker/notmuch')
-rw-r--r-- | worker/notmuch/worker.go | 28 |
1 files 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) } } |