albrow / jobs

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

After-job hook #29

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.

albrow commented 9 years ago

@utrack thanks for writing this up :) The change looks pretty good to me and after I've tested it I want to get it merged into master.

Could you please review the Contribution Guidelines? Specifically, I would like you to create a feature branch off of the master branch and then create a new PR to merge your feature branch into the develop branch. Doing PRs this way helps me maintain a sane git history and increment version numbers correctly.

utrack commented 9 years ago

@albrow Whoopsie! Was in a hurry.