Is there a way to check a condition inside perform in a Sidekiq worker, and to reschedule the job in a different time (and stop executing the job)?
def perform
 if is_it_summer_yet?
   Bear.wake_em_up
 else
   # reschedule to perform in a few hours
 end
end
this is a simple example, but in my use case there are a lot of calculations and network calls for that condition, so I can't do it externally
To run sidekiq, you will need to open a terminal, navigate to your application's directory, and start the sidekiq process, exactly as you would start a web server for the application itself. When the command executes you will see a message that sidekiq has started.
def perform
  if is_it_summer_yet?
    Bear.wake_em_up
  else
    self.class.perform_in(1.hour)
  end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With