How to get job context info in NewFunctionJob callback ?
zhangjie2012 opened this issue · 3 comments
zhangjie2012 commented
e.g:
functionJob := job.NewFunctionJob(func(ctx context.Context) (int, error) {
// get which job id tiggered in here
return 42, nil
})
in fact, I want add more job params to callback.
reugn commented
@zhangjie2012, it makes sense to me to add the JobKey
details of the job to the context, but may I ask the reason you need it? JobDetailOptions
also can be made available. What other information would you expect to be accessible within the context?
zhangjie2012 commented
Finally, I solved it using this way:
callbackJob := job.NewFunctionJob(func(_ context.Context) (n int, err error) {
ctx := CronJobCtx{
// cronjob runtime info, like name/id/params
}
err = handleCronJob(&ctx)
return
})
zhangjie2012 commented
package gocron's implementation is elegant. like:
gocron.NewTask(
func(a string, b int) {
// do things
},
"hello",
1,
),
)
a common requirement is to inject some runtime parameters to my callback function.