Module: Shoryuken::Worker::ClassMethods
- Defined in:
- lib/shoryuken/worker.rb
Instance Method Summary collapse
- #auto_delete? ⇒ Boolean
- #auto_visibility_timeout? ⇒ Boolean
- #exponential_backoff? ⇒ 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_class_attribute(*attrs) ⇒ Object
:nodoc:.
- #shoryuken_options(opts = {}) ⇒ Object
-
#stringify_keys(hash) ⇒ Object
:nodoc:.
Instance Method Details
#auto_delete? ⇒ Boolean
38 39 40 |
# File 'lib/shoryuken/worker.rb', line 38 def auto_delete? !!(['delete'] || ['auto_delete']) end |
#auto_visibility_timeout? ⇒ Boolean
30 31 32 |
# File 'lib/shoryuken/worker.rb', line 30 def auto_visibility_timeout? !!['auto_visibility_timeout'] end |
#exponential_backoff? ⇒ Boolean
34 35 36 |
# File 'lib/shoryuken/worker.rb', line 34 def exponential_backoff? !!['retry_intervals'] end |
#get_shoryuken_options ⇒ Object
:nodoc:
42 43 44 |
# File 'lib/shoryuken/worker.rb', line 42 def # :nodoc: || Shoryuken. end |
#perform_async(body, options = {}) ⇒ Object
9 10 11 |
# File 'lib/shoryuken/worker.rb', line 9 def perform_async(body, = {}) Shoryuken.worker_executor.perform_async(self, body, ) end |
#perform_in(interval, body, options = {}) ⇒ Object Also known as: perform_at
13 14 15 |
# File 'lib/shoryuken/worker.rb', line 13 def perform_in(interval, body, = {}) Shoryuken.worker_executor.perform_in(self, interval, body, ) end |
#server_middleware {|@_server_chain| ... } ⇒ Object
19 20 21 22 23 |
# File 'lib/shoryuken/worker.rb', line 19 def server_middleware @_server_chain ||= Shoryuken.server_middleware.dup yield @_server_chain if block_given? @_server_chain end |
#shoryuken_class_attribute(*attrs) ⇒ Object
:nodoc:
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/shoryuken/worker.rb', line 52 def shoryuken_class_attribute(*attrs) # :nodoc: attrs.each do |name| singleton_class.instance_eval do undef_method(name) if method_defined?(name) || private_method_defined?(name) end define_singleton_method(name) { nil } ivar = "@#{name}" singleton_class.instance_eval do m = "#{name}=" undef_method(m) if method_defined?(m) || private_method_defined?(m) end define_singleton_method("#{name}=") do |val| singleton_class.class_eval do undef_method(name) if method_defined?(name) || private_method_defined?(name) define_method(name) { val } end # singleton? backwards compatibility for ruby < 2.1 singleton_klass = respond_to?(:singleton?) ? singleton? : self != ancestors.first if singleton_klass class_eval do undef_method(name) if method_defined?(name) || private_method_defined?(name) define_method(name) do if instance_variable_defined? ivar instance_variable_get ivar else singleton_class.send name end end end end val end # instance reader undef_method(name) if method_defined?(name) || private_method_defined?(name) define_method(name) do if instance_variable_defined?(ivar) instance_variable_get ivar else self.class.public_send name end end # instance writer m = "#{name}=" undef_method(m) if method_defined?(m) || private_method_defined?(m) attr_writer name end end |
#shoryuken_options(opts = {}) ⇒ Object
25 26 27 28 |
# File 'lib/shoryuken/worker.rb', line 25 def (opts = {}) self. = .merge(stringify_keys(opts || {})) normalize_worker_queue! end |
#stringify_keys(hash) ⇒ Object
:nodoc:
46 47 48 49 50 |
# File 'lib/shoryuken/worker.rb', line 46 def stringify_keys(hash) # :nodoc: new_hash = {} hash.each { |key, value| new_hash[key.to_s] = value } new_hash end |