Module: Shoryuken::Worker::ClassMethods
- Defined in:
- lib/shoryuken/worker.rb
Instance Method Summary collapse
-
#auto_delete? ⇒ Boolean
Checks if automatic message deletion is enabled for this worker.
-
#auto_visibility_timeout? ⇒ Boolean
Checks if automatic visibility timeout extension is enabled for this worker.
-
#exponential_backoff? ⇒ Boolean
Checks if exponential backoff retry is configured for this worker.
-
#get_shoryuken_options ⇒ Object
:nodoc:.
-
#perform_async(body, options = {}) ⇒ String
Enqueues a job to be processed asynchronously by a Shoryuken worker.
-
#perform_in(interval, body, options = {}) ⇒ String
(also: #perform_at)
Enqueues a job to be processed after a specified time interval.
-
#server_middleware {|Shoryuken::Middleware::Chain| ... } ⇒ Shoryuken::Middleware::Chain
Configures server-side middleware chain for this worker class.
-
#shoryuken_class_attribute(*attrs) ⇒ Object
:nodoc:.
-
#shoryuken_options(opts = {}) ⇒ Object
Configures worker options including queue assignment, processing behavior, and SQS-specific settings.
-
#stringify_keys(hash) ⇒ Object
:nodoc:.
Instance Method Details
#auto_delete? ⇒ Boolean
Checks if automatic message deletion is enabled for this worker. When enabled, successfully processed messages are automatically deleted from the SQS queue. When disabled, you must manually delete messages or they will become visible again after the visibility timeout.
211 212 213 |
# File 'lib/shoryuken/worker.rb', line 211 def auto_delete? !!(['delete'] || ['auto_delete']) end |
#auto_visibility_timeout? ⇒ Boolean
Checks if automatic visibility timeout extension is enabled for this worker. When enabled, Shoryuken automatically extends the message visibility timeout during processing to prevent the message from becoming visible to other consumers.
177 178 179 |
# File 'lib/shoryuken/worker.rb', line 177 def auto_visibility_timeout? !!['auto_visibility_timeout'] end |
#exponential_backoff? ⇒ Boolean
Checks if exponential backoff retry is configured for this worker. When retry intervals are specified, failed jobs will be retried with increasing delays between attempts.
192 193 194 |
# File 'lib/shoryuken/worker.rb', line 192 def exponential_backoff? !!['retry_intervals'] end |
#get_shoryuken_options ⇒ Object
:nodoc:
215 216 217 |
# File 'lib/shoryuken/worker.rb', line 215 def # :nodoc: || Shoryuken. end |
#perform_async(body, options = {}) ⇒ String
Enqueues a job to be processed asynchronously by a Shoryuken worker.
65 66 67 |
# File 'lib/shoryuken/worker.rb', line 65 def perform_async(body, = {}) Shoryuken.worker_executor.perform_async(self, body, ) end |
#perform_in(interval, body, options = {}) ⇒ String Also known as: perform_at
Enqueues a job to be processed after a specified time interval.
81 82 83 |
# File 'lib/shoryuken/worker.rb', line 81 def perform_in(interval, body, = {}) Shoryuken.worker_executor.perform_in(self, interval, body, ) end |
#server_middleware {|Shoryuken::Middleware::Chain| ... } ⇒ Shoryuken::Middleware::Chain
Configures server-side middleware chain for this worker class. Middleware runs before and after job processing, similar to Rack middleware.
102 103 104 105 106 |
# File 'lib/shoryuken/worker.rb', line 102 def server_middleware @_server_chain ||= Shoryuken.server_middleware.dup yield @_server_chain if block_given? @_server_chain end |
#shoryuken_class_attribute(*attrs) ⇒ Object
:nodoc:
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/shoryuken/worker.rb', line 225 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
Configures worker options including queue assignment, processing behavior, and SQS-specific settings. This is the main configuration method for workers.
165 166 167 168 |
# File 'lib/shoryuken/worker.rb', line 165 def (opts = {}) self. = .merge(stringify_keys(opts || {})) normalize_worker_queue! end |
#stringify_keys(hash) ⇒ Object
:nodoc:
219 220 221 222 223 |
# File 'lib/shoryuken/worker.rb', line 219 def stringify_keys(hash) # :nodoc: new_hash = {} hash.each { |key, value| new_hash[key.to_s] = value } new_hash end |