0.0
No release in over 3 years
Low commit activity in last 3 years
Adds perform_sync next to perform_async
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.16
= 2.14.2, ~> 2.14
= 4.7.3, ~> 4.7
= 0.1.0, ~> 0.1
= 0.1.2, ~> 0.1
~> 10.0
~> 3.0

Runtime

~> 5.0
 Project Readme

sidekiq-sync

Adds perform_sync to Sidekiq to get the return value from perform while still executing through Sidekiq (distributed workers!). Internally it stores the result in a unique queue that is polled.

install

gem install 'sidekiq-sync'

usage

class HardWorker
  include Sidekiq::Sync::Worker

  def perform(how_hard="super hard", how_long=1)
    puts "working #{how_hard}"
    sleep how_long
    "I worked #{how_hard}"
  end
end

puts HardWorker.perform_sync("really hard")
# outputs "I worked really hard"

puts HardWorker.perform_async("really hard")
# outputs the sidekiq job..

options = Sidekiq::Sync::Options.new(timeout: 3)
puts HardWorker.perform_sync(options, "really hard", 4)
# times out in 3 seconds and raises Sidekiq::Sync::TimeoutError

options = Sidekiq::Sync::Options.new(timeout: 3, raise: false)
puts HardWorker.perform_sync(options, "really hard", 4)
# times out in 3 seconds, returns nil, does not raise

options = Sidekiq::Sync::Options.new(timeout: 3, raise: false)
puts HardWorker.perform_sync(options, "really hard", 4)
# times out in 3 seconds, returns nil, does not raise

options = Sidekiq::Sync::Options.new(timeout: 3, raise: false)
puts HardWorker.perform_sync("really hard", options, 4)
# options can be wherever you wish (still sleeps 4, timeouts in 3 and does not raise)