Class: Qwirk::Adapter::Base::WorkerConfig
- Inherits:
-
Object
- Object
- Qwirk::Adapter::Base::WorkerConfig
- Includes:
- Rumx::Bean
- Defined in:
- lib/qwirk/adapter/base/worker_config.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#adapter_factory ⇒ Object
readonly
Make explicit the instance variables available to the derived adapter classes.
-
#default_options ⇒ Object
readonly
Make explicit the instance variables available to the derived adapter classes.
-
#manager ⇒ Object
readonly
Make explicit the instance variables available to the derived adapter classes.
-
#marshal_sym ⇒ Object
readonly
Make explicit the instance variables available to the derived adapter classes.
-
#marshaler ⇒ Object
readonly
Make explicit the instance variables available to the derived adapter classes.
-
#name ⇒ Object
readonly
Make explicit the instance variables available to the derived adapter classes.
-
#options ⇒ Object
readonly
Make explicit the instance variables available to the derived adapter classes.
-
#queue_name ⇒ Object
Returns the value of attribute queue_name.
-
#queue_options ⇒ Object
readonly
Make explicit the instance variables available to the derived adapter classes.
-
#response_options ⇒ Object
readonly
Make explicit the instance variables available to the derived adapter classes.
-
#topic_name ⇒ Object
Returns the value of attribute topic_name.
-
#worker_class ⇒ Object
readonly
Make explicit the instance variables available to the derived adapter classes.
Class Method Summary collapse
- .default_marshal_sym ⇒ Object
-
.in_process?(config) ⇒ Boolean
By default, workers do not run in the same process as the publishers.
-
.initial_default_config ⇒ Object
Define the default config values for the attributes all workers will share.
Instance Method Summary collapse
-
#bean_attributes_changed ⇒ Object
Override rumx bean method.
-
#init ⇒ Object
Allow extensions to initialize before setting the attributes.
-
#initialize(adapter_factory, name, manager, worker_class, default_options, options) ⇒ WorkerConfig
constructor
Create new WorkerConfig to manage workers of a common class.
- #join(timeout = nil) ⇒ Object
- #marshal_response(object) ⇒ Object
- #periodic_call(poll_time) ⇒ Object
- #stop ⇒ Object
- #stopped? ⇒ Boolean
- #to_s ⇒ Object
- #unmarshal_response(marshaled_object) ⇒ Object
- #worker_stopped(worker) ⇒ Object
Constructor Details
#initialize(adapter_factory, name, manager, worker_class, default_options, options) ⇒ WorkerConfig
Create new WorkerConfig to manage workers of a common class
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 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 |
# File 'lib/qwirk/adapter/base/worker_config.rb', line 32 def initialize(adapter_factory, name, manager, worker_class, , ) @adapter_factory = adapter_factory @name = name @manager = manager @worker_class = worker_class @default_options = .dup @options = .dup # First option is getting the queue or topic from the given options @queue_name = .delete(:queue_name) @topic_name = !@queue_name && .delete(:queue_name) # Second option is getting them from the default options @queue_name ||= !@topic_name && .delete(:queue_name) @topic_name ||= !@queue_name && .delete(:topic_name) # Third (and most likely) option is getting it based on the class topic or queue DSL or defaulting to the default queue @queue_name ||= !@topic_name && worker_class.queue_name(@name) @topic_name ||= !@queue_name && worker_class.topic_name if @queue_name = (.delete(:queue_options) || {}).merge(.delete(:queue_options) || {}) else = (.delete(:topic_options) || {}).merge(.delete(:topic_options) || {}) end @queue_options = worker_class..merge() @response_options = @queue_options[:response] || {} # Defines how we will marshal the response @marshal_sym = ([:marshal] || self.class.default_marshal_sym) @marshaler = MarshalStrategy.find(@marshal_sym) @log_times = adapter_factory.log_times init #Qwirk.logger.debug { "options=#{options.inspect}" } .each do |key, value| begin send(key.to_s+'=', value) rescue Exception => e # Let config_reader's set a default value begin instance_variable_set("@#{key}", value) rescue Exception => e Qwirk.logger.debug "DEBUG: During initialization of #{worker_class.name} config=#{@name}, default assignment of #{key}=#{value} was ignored" end end end # Run the specified options after the default options, so that codependant options don't get overwritten (like min_count/max_count) .each do |key, value| begin send(key.to_s+'=', value) rescue Exception => e Qwirk.logger.debug "DEBUG: During initialization of #{worker_class.name} config=#{@name}, assignment of #{key}=#{value} was ignored" end end end |
Instance Attribute Details
#adapter_factory ⇒ Object (readonly)
Make explicit the instance variables available to the derived adapter classes
10 11 12 |
# File 'lib/qwirk/adapter/base/worker_config.rb', line 10 def adapter_factory @adapter_factory end |
#default_options ⇒ Object (readonly)
Make explicit the instance variables available to the derived adapter classes
10 11 12 |
# File 'lib/qwirk/adapter/base/worker_config.rb', line 10 def @default_options end |
#manager ⇒ Object (readonly)
Make explicit the instance variables available to the derived adapter classes
10 11 12 |
# File 'lib/qwirk/adapter/base/worker_config.rb', line 10 def manager @manager end |
#marshal_sym ⇒ Object (readonly)
Make explicit the instance variables available to the derived adapter classes
10 11 12 |
# File 'lib/qwirk/adapter/base/worker_config.rb', line 10 def marshal_sym @marshal_sym end |
#marshaler ⇒ Object (readonly)
Make explicit the instance variables available to the derived adapter classes
10 11 12 |
# File 'lib/qwirk/adapter/base/worker_config.rb', line 10 def marshaler @marshaler end |
#name ⇒ Object (readonly)
Make explicit the instance variables available to the derived adapter classes
10 11 12 |
# File 'lib/qwirk/adapter/base/worker_config.rb', line 10 def name @name end |
#options ⇒ Object (readonly)
Make explicit the instance variables available to the derived adapter classes
10 11 12 |
# File 'lib/qwirk/adapter/base/worker_config.rb', line 10 def @options end |
#queue_name ⇒ Object
Returns the value of attribute queue_name.
12 13 14 |
# File 'lib/qwirk/adapter/base/worker_config.rb', line 12 def queue_name @queue_name end |
#queue_options ⇒ Object (readonly)
Make explicit the instance variables available to the derived adapter classes
10 11 12 |
# File 'lib/qwirk/adapter/base/worker_config.rb', line 10 def @queue_options end |
#response_options ⇒ Object (readonly)
Make explicit the instance variables available to the derived adapter classes
10 11 12 |
# File 'lib/qwirk/adapter/base/worker_config.rb', line 10 def @response_options end |
#topic_name ⇒ Object
Returns the value of attribute topic_name.
12 13 14 |
# File 'lib/qwirk/adapter/base/worker_config.rb', line 12 def topic_name @topic_name end |
#worker_class ⇒ Object (readonly)
Make explicit the instance variables available to the derived adapter classes
10 11 12 |
# File 'lib/qwirk/adapter/base/worker_config.rb', line 10 def worker_class @worker_class end |
Class Method Details
.default_marshal_sym ⇒ Object
22 23 24 |
# File 'lib/qwirk/adapter/base/worker_config.rb', line 22 def self.default_marshal_sym :ruby end |
.in_process?(config) ⇒ Boolean
By default, workers do not run in the same process as the publishers
27 28 29 |
# File 'lib/qwirk/adapter/base/worker_config.rb', line 27 def self.in_process?(config) false end |
.initial_default_config ⇒ Object
Define the default config values for the attributes all workers will share. These will be sent as options to the constructor
18 19 20 |
# File 'lib/qwirk/adapter/base/worker_config.rb', line 18 def self.initial_default_config {} end |
Instance Method Details
#bean_attributes_changed ⇒ Object
Override rumx bean method
105 106 107 108 |
# File 'lib/qwirk/adapter/base/worker_config.rb', line 105 def bean_attributes_changed super @manager.save_persist_state end |
#init ⇒ Object
Allow extensions to initialize before setting the attributes
88 89 |
# File 'lib/qwirk/adapter/base/worker_config.rb', line 88 def init end |
#join(timeout = nil) ⇒ Object
94 95 |
# File 'lib/qwirk/adapter/base/worker_config.rb', line 94 def join(timeout=nil) end |
#marshal_response(object) ⇒ Object
110 111 112 |
# File 'lib/qwirk/adapter/base/worker_config.rb', line 110 def marshal_response(object) @marshaler.marshal(object) end |
#periodic_call(poll_time) ⇒ Object
118 119 |
# File 'lib/qwirk/adapter/base/worker_config.rb', line 118 def periodic_call(poll_time) end |
#stop ⇒ Object
91 92 |
# File 'lib/qwirk/adapter/base/worker_config.rb', line 91 def stop end |
#stopped? ⇒ Boolean
97 98 99 |
# File 'lib/qwirk/adapter/base/worker_config.rb', line 97 def stopped? self.manager.stopped? end |
#to_s ⇒ Object
121 122 123 |
# File 'lib/qwirk/adapter/base/worker_config.rb', line 121 def to_s @name end |
#unmarshal_response(marshaled_object) ⇒ Object
114 115 116 |
# File 'lib/qwirk/adapter/base/worker_config.rb', line 114 def unmarshal_response(marshaled_object) @marshaler.unmarshal(marshaled_object) end |
#worker_stopped(worker) ⇒ Object
101 102 |
# File 'lib/qwirk/adapter/base/worker_config.rb', line 101 def worker_stopped(worker) end |