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
53 54 55 |
# File 'lib/shoryuken/worker.rb', line 53 def auto_visibility_timeout? !!['auto_visibility_timeout'] end |
#get_shoryuken_options ⇒ Object
:nodoc:
57 58 59 |
# File 'lib/shoryuken/worker.rb', line 57 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' } body = JSON.dump(body) if body.is_a?(Hash) [:message_body] = body 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 46 47 48 49 50 51 |
# File 'lib/shoryuken/worker.rb', line 42 def (opts = {}) @shoryuken_options = .merge(stringify_keys(Hash(opts))) queue = @shoryuken_options['queue'] if queue.respond_to? :call queue = queue.call @shoryuken_options['queue'] = queue end Shoryuken.register_worker(queue, self) end |
#stringify_keys(hash) ⇒ Object
:nodoc:
61 62 63 64 65 66 |
# File 'lib/shoryuken/worker.rb', line 61 def stringify_keys(hash) # :nodoc: hash.keys.each do |key| hash[key.to_s] = hash.delete(key) end hash end |