Alex Antonov
Alex Antonov

Reputation: 15216

sidekiq two methods on delay

How I can do something like that at sidekiq?

Gateway::AddUser.delay.new(6).call

For now, Gateway::AddUser.delay.new(6) return a string, and call method trying to run on it. But I want to call just Gateway::AddUser.new(6).call delayed

Upvotes: 1

Views: 1134

Answers (2)

Alex Antonov
Alex Antonov

Reputation: 15216

Solved just like this:

Gateway::AddUser.delay.perform(6)

Where perform method is:

def self.perform(params)
  new(params).call
end

Just rewrite 2 methods to 1 =)

Upvotes: 3

André Barbosa
André Barbosa

Reputation: 518

why don't you just wrap that in other method?

class User
  def self.add_user_via_gateway(attributes)
    Gateway::AddUser.new(attributes).call
  end
end

User.delay.add_user_via_gatway(attributes)

EDIT:

If you prefer, you can also create a worker class.

class AddUserViaGatewayWorker
  include Sidekiq::Worker

  def perform(attributes)
    Gateway::AddUser.new(attributes).call
  end
end

AddUserViaGatewayWorker.perform_async(attributes)

Upvotes: 1

Related Questions