Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reschedule a sidekiq job from within perform

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

like image 595
Nick Ginanto Avatar asked Aug 12 '15 10:08

Nick Ginanto


People also ask

How do I manually run a Sidekiq job?

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.


1 Answers

def perform
  if is_it_summer_yet?
    Bear.wake_em_up
  else
    self.class.perform_in(1.hour)
  end
end
like image 61
Mike Perham Avatar answered Oct 05 '22 06:10

Mike Perham