-
Notifications
You must be signed in to change notification settings - Fork 4
Description
One of my coworkers argued that using a middleware (+ the repeat { } configuration at class-level) was overly complicated, and that instead one could just have an instance method reschedule that is manually called inside perform.
For example:
class TestJob
include Sidekiq::Worker
include Sidekiq::Repeat::Repeatable
def perform
# ... do some work
ensure
reschedule 1.hour # or cron pattern, or whatever
end
endBasically, with this, you don't even need the gem at all anymore, since you could simply call self.class.perform_in and be set. However, of course you'd still need a way to schedule jobs (or ensure their scheduledness) at boot time, and you would probably add some boilerplate around it, ending up at the gem solution after all.
So, I'd generally argue that the perceived simplicity gain would quickly fade away, as sidekiq-repeat itself is already super simple.
The one benefit I do see with this is the additional level of control it provides you. You could easily change your reschedule pattern according to criteria you choose yourself (e.g. previous run duration), or you could even choose to not reschedule at all. Do you think this would be a good feature to have?
Changes required:
- A new instance level
reschedule { cron_line_or_ice_cube_expr }method that redirects to class-levelreschedule - Class-level
reschedulewould need an optional cronline, and only if that isnilwould ask for the the class configurationcronline
Not sure if this really makes sense, but obviously I'm trying to find a way to sell sidekiq-repeat :)