user3834491
user3834491

Reputation: 29

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?

Upvotes: 1

Views: 1276

Answers (1)

andreimarinescu
andreimarinescu

Reputation: 3641

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.

Upvotes: 1

Related Questions