2012-05-01 18:54:04 -04:00
|
|
|
module Sidekiq
|
2012-09-07 11:59:04 -04:00
|
|
|
class Client
|
2012-05-01 18:54:04 -04:00
|
|
|
|
|
|
|
##
|
2012-09-07 11:59:04 -04:00
|
|
|
# The Sidekiq inline infrastructure overrides perform_async so that it
|
2012-05-01 18:54:04 -04:00
|
|
|
# actually calls perform instead. This allows workers to be run inline in a
|
|
|
|
# testing environment.
|
|
|
|
#
|
|
|
|
# This is similar to `Resque.inline = true` functionality.
|
|
|
|
#
|
|
|
|
# Example:
|
|
|
|
#
|
|
|
|
# require 'sidekiq/testing/inline'
|
|
|
|
#
|
|
|
|
# $external_variable = 0
|
|
|
|
#
|
|
|
|
# class ExternalWorker
|
|
|
|
# include Sidekiq::Worker
|
|
|
|
#
|
|
|
|
# def perform
|
|
|
|
# $external_variable = 1
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# assert_equal 0, $external_variable
|
|
|
|
# ExternalWorker.perform_async
|
|
|
|
# assert_equal 1, $external_variable
|
|
|
|
#
|
2012-09-07 11:59:04 -04:00
|
|
|
singleton_class.class_eval do
|
2012-10-25 23:55:32 -04:00
|
|
|
alias_method :raw_push_old, :raw_push
|
2012-11-19 20:34:46 -05:00
|
|
|
def raw_push(normed, payload)
|
|
|
|
Array.wrap(payload).each do |hash|
|
|
|
|
normed['class'].constantize.new.perform(*Sidekiq.load_json(hash)['args'])
|
|
|
|
end
|
|
|
|
|
2012-05-01 18:54:04 -04:00
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|