Class: Shoryuken::Options
- Inherits:
-
Object
- Object
- Shoryuken::Options
- Defined in:
- lib/shoryuken/options.rb
Constant Summary collapse
- DEFAULTS =
{ thread_priority: -1, concurrency: 25, queues: [], aws: {}, delay: 0.0, timeout: 8, lifecycle_events: { startup: [], dispatch: [], utilization_update: [], quiet: [], shutdown: [], stopped: [] } }.freeze
Instance Attribute Summary collapse
-
#active_job_queue_name_prefixing ⇒ Object
Returns the value of attribute active_job_queue_name_prefixing.
-
#cache_visibility_timeout ⇒ Object
Returns the value of attribute cache_visibility_timeout.
- #default_worker_options ⇒ Object
-
#enable_reloading ⇒ Object
Returns the value of attribute enable_reloading.
-
#exception_handlers ⇒ Object
Returns the value of attribute exception_handlers.
-
#groups ⇒ Object
Returns the value of attribute groups.
-
#launcher_executor ⇒ Object
Returns the value of attribute launcher_executor.
- #logger ⇒ Object
-
#reloader ⇒ Object
Returns the value of attribute reloader.
- #sqs_client ⇒ Object
-
#sqs_client_receive_message_opts ⇒ Object
Returns the value of attribute sqs_client_receive_message_opts.
-
#start_callback ⇒ Object
Returns the value of attribute start_callback.
-
#stop_callback ⇒ Object
Returns the value of attribute stop_callback.
-
#worker_executor ⇒ Object
Returns the value of attribute worker_executor.
-
#worker_registry ⇒ Object
Returns the value of attribute worker_registry.
Instance Method Summary collapse
- #active_job? ⇒ Boolean
- #active_job_queue_name_prefixing? ⇒ Boolean
- #add_group(group, concurrency = nil, delay: nil) ⇒ Object
- #add_queue(queue, weight, group) ⇒ Object
- #cache_visibility_timeout? ⇒ Boolean
- #client_middleware {|@_client_chain| ... } ⇒ Object
- #configure_client {|_self| ... } ⇒ Object
- #configure_server {|_self| ... } ⇒ Object
- #delay(group) ⇒ Object
-
#initialize ⇒ Options
constructor
A new instance of Options.
-
#on(event, &block) ⇒ Object
Register a block to run at a point in the Shoryuken lifecycle.
- #on_start(&block) ⇒ Object
- #on_stop(&block) ⇒ Object
- #options ⇒ Object
- #polling_strategy(group) ⇒ Object
- #register_worker(*args) ⇒ Object
- #server? ⇒ Boolean
- #server_middleware {|@_server_chain| ... } ⇒ Object
- #thread_priority ⇒ Object
- #ungrouped_queues ⇒ Object
Constructor Details
#initialize ⇒ Options
Returns a new instance of Options.
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/shoryuken/options.rb', line 30 def initialize self.groups = {} self.worker_registry = DefaultWorkerRegistry.new self.exception_handlers = [DefaultExceptionHandler] self.active_job_queue_name_prefixing = false self.worker_executor = Worker::DefaultExecutor self.cache_visibility_timeout = false self.reloader = proc { |&block| block.call } self.enable_reloading ||= false # this is needed for keeping backward compatibility @sqs_client_receive_message_opts ||= {} end |
Instance Attribute Details
#active_job_queue_name_prefixing ⇒ Object
Returns the value of attribute active_job_queue_name_prefixing.
22 23 24 |
# File 'lib/shoryuken/options.rb', line 22 def active_job_queue_name_prefixing @active_job_queue_name_prefixing end |
#cache_visibility_timeout ⇒ Object
Returns the value of attribute cache_visibility_timeout.
22 23 24 |
# File 'lib/shoryuken/options.rb', line 22 def cache_visibility_timeout @cache_visibility_timeout end |
#default_worker_options ⇒ Object
134 135 136 137 138 139 140 141 142 143 |
# File 'lib/shoryuken/options.rb', line 134 def @default_worker_options ||= { 'queue' => 'default', 'delete' => false, 'auto_delete' => false, 'auto_visibility_timeout' => false, 'retry_intervals' => nil, 'batch' => false } end |
#enable_reloading ⇒ Object
Returns the value of attribute enable_reloading.
22 23 24 |
# File 'lib/shoryuken/options.rb', line 22 def enable_reloading @enable_reloading end |
#exception_handlers ⇒ Object
Returns the value of attribute exception_handlers.
22 23 24 |
# File 'lib/shoryuken/options.rb', line 22 def exception_handlers @exception_handlers end |
#groups ⇒ Object
Returns the value of attribute groups.
22 23 24 |
# File 'lib/shoryuken/options.rb', line 22 def groups @groups end |
#launcher_executor ⇒ Object
Returns the value of attribute launcher_executor.
22 23 24 |
# File 'lib/shoryuken/options.rb', line 22 def launcher_executor @launcher_executor end |
#logger ⇒ Object
102 103 104 |
# File 'lib/shoryuken/options.rb', line 102 def logger @logger ||= Shoryuken::Logging.logger end |
#reloader ⇒ Object
Returns the value of attribute reloader.
22 23 24 |
# File 'lib/shoryuken/options.rb', line 22 def reloader @reloader end |
#sqs_client ⇒ Object
90 91 92 |
# File 'lib/shoryuken/options.rb', line 90 def sqs_client @sqs_client ||= Aws::SQS::Client.new end |
#sqs_client_receive_message_opts ⇒ Object
Returns the value of attribute sqs_client_receive_message_opts.
28 29 30 |
# File 'lib/shoryuken/options.rb', line 28 def @sqs_client_receive_message_opts end |
#start_callback ⇒ Object
Returns the value of attribute start_callback.
22 23 24 |
# File 'lib/shoryuken/options.rb', line 22 def start_callback @start_callback end |
#stop_callback ⇒ Object
Returns the value of attribute stop_callback.
22 23 24 |
# File 'lib/shoryuken/options.rb', line 22 def stop_callback @stop_callback end |
#worker_executor ⇒ Object
Returns the value of attribute worker_executor.
22 23 24 |
# File 'lib/shoryuken/options.rb', line 22 def worker_executor @worker_executor end |
#worker_registry ⇒ Object
Returns the value of attribute worker_registry.
22 23 24 |
# File 'lib/shoryuken/options.rb', line 22 def worker_registry @worker_registry end |
Instance Method Details
#active_job? ⇒ Boolean
43 44 45 |
# File 'lib/shoryuken/options.rb', line 43 def active_job? defined?(::ActiveJob) end |
#active_job_queue_name_prefixing? ⇒ Boolean
176 177 178 |
# File 'lib/shoryuken/options.rb', line 176 def active_job_queue_name_prefixing? @active_job_queue_name_prefixing end |
#add_group(group, concurrency = nil, delay: nil) ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/shoryuken/options.rb', line 47 def add_group(group, concurrency = nil, delay: nil) concurrency ||= [:concurrency] delay ||= [:delay] groups[group] ||= { concurrency: concurrency, delay: delay, queues: [] } end |
#add_queue(queue, weight, group) ⇒ Object
58 59 60 61 62 |
# File 'lib/shoryuken/options.rb', line 58 def add_queue(queue, weight, group) weight.times do groups[group][:queues] << queue end end |
#cache_visibility_timeout? ⇒ Boolean
172 173 174 |
# File 'lib/shoryuken/options.rb', line 172 def cache_visibility_timeout? @cache_visibility_timeout end |
#client_middleware {|@_client_chain| ... } ⇒ Object
128 129 130 131 132 |
# File 'lib/shoryuken/options.rb', line 128 def client_middleware @_client_chain ||= default_client_middleware yield @_client_chain if block_given? @_client_chain end |
#configure_client {|_self| ... } ⇒ Object
124 125 126 |
# File 'lib/shoryuken/options.rb', line 124 def configure_client yield self unless server? end |
#configure_server {|_self| ... } ⇒ Object
114 115 116 |
# File 'lib/shoryuken/options.rb', line 114 def configure_server yield self if server? end |
#delay(group) ⇒ Object
86 87 88 |
# File 'lib/shoryuken/options.rb', line 86 def delay(group) groups[group].to_h.fetch(:delay, [:delay]).to_f end |
#on(event, &block) ⇒ Object
Register a block to run at a point in the Shoryuken lifecycle. :startup, :quiet, :shutdown or :stopped are valid events.
Shoryuken.configure_server do |config|
config.on(:shutdown) do
puts "Goodbye cruel world!"
end
end
161 162 163 164 165 166 |
# File 'lib/shoryuken/options.rb', line 161 def on(event, &block) fail ArgumentError, "Symbols only please: #{event}" unless event.is_a?(Symbol) fail ArgumentError, "Invalid event name: #{event}" unless [:lifecycle_events].key?(event) [:lifecycle_events][event] << block end |
#on_start(&block) ⇒ Object
145 146 147 |
# File 'lib/shoryuken/options.rb', line 145 def on_start(&block) self.start_callback = block end |
#on_stop(&block) ⇒ Object
149 150 151 |
# File 'lib/shoryuken/options.rb', line 149 def on_stop(&block) self.stop_callback = block end |
#options ⇒ Object
98 99 100 |
# File 'lib/shoryuken/options.rb', line 98 def @options ||= DEFAULTS.dup end |
#polling_strategy(group) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/shoryuken/options.rb', line 68 def polling_strategy(group) strategy = (group == 'default' ? : [:groups].to_h[group]).to_h[:polling_strategy] case strategy when 'WeightedRoundRobin', nil # Default case Polling::WeightedRoundRobin when 'StrictPriority' Polling::StrictPriority when String begin Object.const_get(strategy) rescue NameError raise ArgumentError, "#{strategy} is not a valid polling_strategy" end when Class strategy end end |
#register_worker(*args) ⇒ Object
110 111 112 |
# File 'lib/shoryuken/options.rb', line 110 def register_worker(*args) worker_registry.register_worker(*args) end |
#server? ⇒ Boolean
168 169 170 |
# File 'lib/shoryuken/options.rb', line 168 def server? defined?(Shoryuken::CLI) end |
#server_middleware {|@_server_chain| ... } ⇒ Object
118 119 120 121 122 |
# File 'lib/shoryuken/options.rb', line 118 def server_middleware @_server_chain ||= default_server_middleware yield @_server_chain if block_given? @_server_chain end |
#thread_priority ⇒ Object
106 107 108 |
# File 'lib/shoryuken/options.rb', line 106 def thread_priority @thread_priority ||= [:thread_priority] end |
#ungrouped_queues ⇒ Object
64 65 66 |
# File 'lib/shoryuken/options.rb', line 64 def ungrouped_queues groups.values.flat_map { || [:queues] } end |