albrow / jobs

A persistent and flexible background jobs library for go.
MIT License
499 stars 47 forks source link

After-job hook #30

Closed utrack closed 9 years ago

utrack commented 9 years ago

This PR adds a function to the pool that gets executed each time a job is finished. Such function can be useful for monitoring.

I thought about adding a full-fledged middleware chains first, but it would add a lot of complexity without too many benefits. This implementation gets a function which can accept a Job via (Pool).SetAfterFunc() and runs it each time a job is finished regardless of its status, passing the job to the function.

Also, I moved the job.finished assgnment before the error checks (worker.go:85); this way the timings are saved even when the job returned an error.

(resubmitted, previous PR: #29)

albrow commented 9 years ago

Looks great. I'm going to merge this and include it in a new release, hopefully tonight. I'll likely make this 0.4.0 and push back features planned for 0.4.0 to 0.5.0. Thanks again!