Open jrouzierinverse opened 4 years ago
Thanks for the thoughts, but I think you can do this today, because Job is an interface:
type MyJob struct {
Name string
Func func()
}
func (j MyJob) Run() {
j.Func()
}
cron.AddJob(MyJob{"My Name", fn}, ...)
Does that work for your use case?
My issue is with logging and knowing which job is running or going to run. https://github.com/robfig/cron/blob/master/cron.go#L276 for example. Reviewing the log entries can be confusing because it tells me the job Id was wake/added/scheduled/run/removed but that does not give me any clue which job it is. For long-running services, it will not be practical for me to look the name to id mapping in the log. Just to figure out which service is running badly.
Job is an interface, you can made your own and use method Schedule()
I think this is a good idea, because I need to find the Job by name
I suppose this could be implemented as an optional interface that is tested for and used by the logger..
e this could be implemented as an optional interface that is tested for and used by the logger..
would you accept a PR for this? I'd like to add this. The log output becomes much more readable with a name. The chained middleware may also benefit from a name, for example when collecting metrics.
I suppose this could be implemented as an optional interface that is tested for and used by the logger..
The optional interface approach doesn't play nice with job wrappers though.
+1 for job names. The cron logs are garbage. Not only they pollute the stdout but they are utterly useless since they lack job names. I had to write my own logging to dev/null this garbage generation. VERY poor design.
+1 for job.Name()
This library is the historical one, and I am really sorry to say that, but you can use this library instead : https://pkg.go.dev/github.com/go-co-op/gocron/v2#Job
To improve debugging and logging allow Jobs to have a name. I would like to propose the following changes.
If the name is empty. It will be set to the EntryID.
Would you mind if I send you a pull request for this?