two ideas: name, and around trigger
Closed this issue · 1 comments
jjb commented
Here are a couple ideas, let me know what you think and if you might be interested in PRs!
Job Names
It would be nice to name job types so the name could be referred to in error reports and maybe other places (such as below in the "around trigger" idea).
def scheduler.on_error(job, error)
ErrorReporter.track_exception(error, {name: job.name})
end
This can sort of be achieved with keys, but it's a bit of a misuse since it would need to be assigned every time?
# what we can do now
scheduler.schedule_every '1s' do |job|
job[:name] = 'import-new-csvs'
...
end
# maybe this is nicer
scheduler.every '1s', name: 'import-new-csvs' do |job|
...
end
"Around" triggers
We have before and after triggers:
Would be nice to also have around triggers.
def scheduler.on_around_trigger(job, trigger_time)
t = Time.now
puts "triggering job #{job.name} at #{t}"
yield
puts "#{job.name} finished in #{Time.now-t} seconds"
end
It would need to be implemented inside the job thread and not in the master thread.
jmettraux commented
I like both ideas. They are small and I can imagine myself maintaining them in the long term.
Looking forward to the pull requests.
Thanks and best regards.