Module: Shoryuken::Worker::ClassMethods
- Defined in:
- lib/shoryuken/worker.rb
Instance Method Summary collapse
- #auto_visibility_timeout? ⇒ Boolean
-
#get_shoryuken_options ⇒ Object
:nodoc:.
- #perform_async(body, options = {}) ⇒ Object
- #perform_in(interval, body, options = {}) ⇒ Object (also: #perform_at)
- #server_middleware {|@server_chain| ... } ⇒ Object
- #shoryuken_options(opts = {}) ⇒ Object
-
#stringify_keys(hash) ⇒ Object
:nodoc:.
Instance Method Details
#auto_visibility_timeout? ⇒ Boolean
47 48 49 |
# File 'lib/shoryuken/worker.rb', line 47 def auto_visibility_timeout? !!['auto_visibility_timeout'] end |
#get_shoryuken_options ⇒ Object
:nodoc:
51 52 53 |
# File 'lib/shoryuken/worker.rb', line 51 def # :nodoc: @shoryuken_options || Shoryuken. end |
#perform_async(body, options = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/shoryuken/worker.rb', line 8 def perform_async(body, = {}) [:message_attributes] ||= {} [:message_attributes]['shoryuken_class'] = { string_value: self.to_s, data_type: 'String' } [:message_body] = body queue = .delete(:queue) || ['queue'] Shoryuken::Client.queues(queue).() end |
#perform_in(interval, body, options = {}) ⇒ Object Also known as: perform_at
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/shoryuken/worker.rb', line 22 def perform_in(interval, body, = {}) interval = interval.to_f now = Time.now.to_f ts = (interval < 1_000_000_000 ? (now + interval).to_f : interval) delay = (ts - now).ceil raise 'The maximum allowed delay is 15 minutes' if delay > 15 * 60 perform_async(body, .merge(delay_seconds: delay)) end |
#server_middleware {|@server_chain| ... } ⇒ Object
36 37 38 39 40 |
# File 'lib/shoryuken/worker.rb', line 36 def server_middleware @server_chain ||= Shoryuken.server_middleware.dup yield @server_chain if block_given? @server_chain end |
#shoryuken_options(opts = {}) ⇒ Object
42 43 44 45 |
# File 'lib/shoryuken/worker.rb', line 42 def (opts = {}) @shoryuken_options = .merge(stringify_keys(opts || {})) normalize_worker_queue! end |
#stringify_keys(hash) ⇒ Object
:nodoc:
55 56 57 58 59 60 |
# File 'lib/shoryuken/worker.rb', line 55 def stringify_keys(hash) # :nodoc: hash.keys.each do |key| hash[key.to_s] = hash.delete(key) end hash end |