Search code examples
ruby-on-railsredissidekiq

How send request every 2 seconds with Sidekiq?


I have worker that send request to server and checks exist file. Now worker runs at the specified time:

CheckFileWorker.perform_in(@target_file.check_start_date, @target_file.url)

  1. I want run worker every 2 second. How I can do it?
  2. May be need second Worker who will starting first Worker?

Solution

  • I'm using Sidetiq for scheduling recurring background jobs (https://github.com/tobiassvn/sidetiq).

    Basically you should do something similar to this:

    class LicenseCheckerWorker
      include Sidekiq::Worker
      include Sidetiq::Schedulable
    
      recurrence { hourly }
    
      def perform
        #your logic here
      end
    end
    

    Of course you should change the recurrence schedule to reflect your preferences.

    Edit: another way to do this is schedule another run at the end of the #perform logic, delayed by 2 seconds.