Skip to content
This repository has been archived by the owner on Sep 20, 2022. It is now read-only.

After-job hook #30

Merged
merged 2 commits into from Aug 19, 2015
Merged

After-job hook #30

merged 2 commits into from Aug 19, 2015

Conversation

utrack
Copy link
Contributor

@utrack utrack commented Aug 18, 2015

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)

@@ -32,6 +33,8 @@ type Pool struct {
// exit is used to signal the pool to stop running the query loop
// and close the jobs channel
exit chan bool
// afterFunc is a function that gets called after each job.
afterFunc *func(*Job)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct me if I'm wrong, but I don't think this needs to be a pointer to a function? Functions are, by themselves, already nillable. See http://play.golang.org/p/1qA9c70wpJ.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@albrow didn't know about that trick. Neat!
Yeah, that's probably not needed then.

@albrow
Copy link
Owner

albrow commented Aug 19, 2015

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!

albrow added a commit that referenced this pull request Aug 19, 2015
@albrow albrow merged commit 7ea9567 into albrow:develop Aug 19, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants