Comments (5)
@albrow Yeah I guess the SetAfterFunc
's doc is a bit misleading in a way that it executes after a job is finished (whether success or failure) and the job also contains an error object (since a successful job shouldn't contain an error) on it so I naturally thought thats how its done.
Anyway some of our jobs are very large and there are ton's of errors happening in the process. And since your RegisterType func already expects an error to be returned whenever some thing goes wrong in the handler it can send this error and the job to a default error handler which will notify us of the error and provide us more context on it and not just an error.
We use echo router and it has a really neat error handling mechanism . See echo router's default error handling mechanism DefaultHTTPErrorHandler. We get the error and even a context object on where it happend and this could help us more in fixing bugs in production.
And maybe a panic handler for the job will also be useful.
We could do the handleErr(err)
func like you said but I was thinking this would make it more easier from a coding perspective and maybe we could also save these failed jobs somewhere (maybe postgres) so that we could retry them or list them later.
from jobs.
We also need to have a common panic handler for the jobs since recently one of the jobs panic'ked and killed our server. So for now I'm manually doing a defer HandlePanic() for it just to be safe in each job.
edit: Oh wait your's does have a panic handler this happened because of this https://github.com/carlescere/scheduler forgot to switch this in the other branch
from jobs.
Just a heads up,
Right now I do my error handling like this
catchError := func(process func() (*Context, error)) error {
defer HandlePanic()
context, err := process()
if err != nil {
MakeStackTrace(context, err)
}
logger.Warn("Job Error", "err", err)
return err
}
jobs.RegisterType("email", 3, func(params *Message) error {
return catchError(func() (*Context, error) {
}
}
This does make it easier a liitle bit.
from jobs.
I tried this but this doesn't return the error that caused the job to fail
jobPool.SetAfterFunc(func(j *jobs.Job) {
err := j.Error()
})
from jobs.
@pyros2097 thanks for bringing this up.
The documentation for SetAfterFunc
states:
SetAfterFunc will assign a function that will be executed each time a job is finished.
This means that the function will not be executed if there is an error. I'm sorry if that is not clear. Do you think we could improve the wording?
Secondly, I'm not sure if this use case warrants the addition of a new feature. It seems like you should be able to write your own error handler function and then call it whenever there is an error. Something like this:
func handleErr(j *jobs.Job, err error) {
// Log the error and do whatever else you need to do here.
}
// When registering the job, we can handle the error manually.
welcomeEmailJobs, err := jobs.RegisterType("welcomeEmail", 3, func(user *User) error {
msg := fmt.Sprintf("Hello, %s! Thanks for signing up for foo.com.", user.Name)
if err := emails.Send(user.EmailAddress, msg); err != nil {
// Before returning the erorr, call handleErr
handleErr(err)
return err
}
})
You know more about your code than I do. Do you think this would work? Or do you think we need a new feature for this?
from jobs.
Related Issues (20)
- Use go generate to convert lua script files to strings HOT 4
- Use an interface for jobs instead of a non-type-safe handler function (would break backwards-compatibility) HOT 4
- Support redis sentinel HOT 6
- Export job.freq HOT 4
- Reschedule with freq HOT 2
- FindById() doesn't return error for missing jobs HOT 7
- Add a changelog HOT 2
- Panic in xen container HOT 4
- Job runtime error messages should include a stack trace
- Error when calling Destroy() from within a job handler function HOT 8
- job not exec with panic HOT 8
- FindById and job identifiers/human names HOT 6
- Examples?
- Passing params / string name of job. HOT 2
- Endless loop? HOT 6
- Application can't start due to error which message is 'jobs: In scanJob: Could not find Type with name = %s' HOT 1
- super slow HOT 1
- Support environmental prefix
- Job status is changed to executing but job has not started execution
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jobs.