Class: ProcessBalancer::Base
- Inherits:
-
Object
- Object
- ProcessBalancer::Base
- Defined in:
- lib/process_balancer/base.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#worker_index ⇒ Object
readonly
Returns the value of attribute worker_index.
Class Method Summary collapse
Instance Method Summary collapse
- #after_perform ⇒ Object
- #before_perform ⇒ Object
-
#initialize(worker_index, options = {}) ⇒ Base
constructor
A new instance of Base.
- #job_id ⇒ Object
- #lock_records ⇒ Object
- #perform ⇒ Object
- #process_record(record) ⇒ Object
- #runtime_lock_timeout ⇒ Object
- #status_abort ⇒ Object
- #status_sleep(duration) ⇒ Object
- #unlock_records ⇒ Object
- #worker_lock(&_block) ⇒ Object
Constructor Details
#initialize(worker_index, options = {}) ⇒ Base
Returns a new instance of Base.
22 23 24 25 |
# File 'lib/process_balancer/base.rb', line 22 def initialize(worker_index, = {}) @worker_index = worker_index @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/process_balancer/base.rb', line 5 def @options end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
5 6 7 |
# File 'lib/process_balancer/base.rb', line 5 def status @status end |
#worker_index ⇒ Object (readonly)
Returns the value of attribute worker_index.
5 6 7 |
# File 'lib/process_balancer/base.rb', line 5 def worker_index @worker_index end |
Class Method Details
.lock_driver(driver) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/process_balancer/base.rb', line 7 def self.lock_driver(driver) if driver.is_a?(Symbol) file = "process_balancer/lock/#{driver}" driver = driver.to_s unless driver !~ /_/ && driver =~ /[A-Z]+.*/ driver = driver.split('_').map(&:capitalize).join end require file klass = ProcessBalancer::Lock.const_get(driver) include klass else raise ArgumentError, 'Please pass a symbol for the driver to use' end end |
Instance Method Details
#after_perform ⇒ Object
62 |
# File 'lib/process_balancer/base.rb', line 62 def after_perform; end |
#before_perform ⇒ Object
60 |
# File 'lib/process_balancer/base.rb', line 60 def before_perform; end |
#job_id ⇒ Object
56 57 58 |
# File 'lib/process_balancer/base.rb', line 56 def job_id [:id] end |
#lock_records ⇒ Object
64 65 66 |
# File 'lib/process_balancer/base.rb', line 64 def lock_records raise NotImplementedError end |
#perform ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/process_balancer/base.rb', line 27 def perform before_perform worker_lock do |lock| @status = nil records = lock_records lock.extend! records&.each do |r| process_record(r) lock.extend! end @status ensure unlock_records after_perform end end |
#process_record(record) ⇒ Object
72 73 74 |
# File 'lib/process_balancer/base.rb', line 72 def process_record(record) raise NotImplementedError end |
#runtime_lock_timeout ⇒ Object
52 53 54 |
# File 'lib/process_balancer/base.rb', line 52 def runtime_lock_timeout [:runtime_lock_timeout] || 30 end |
#status_abort ⇒ Object
44 45 46 |
# File 'lib/process_balancer/base.rb', line 44 def status_abort @status = :abort end |
#status_sleep(duration) ⇒ Object
48 49 50 |
# File 'lib/process_balancer/base.rb', line 48 def status_sleep(duration) @status = [:sleep, duration] end |
#unlock_records ⇒ Object
68 69 70 |
# File 'lib/process_balancer/base.rb', line 68 def unlock_records raise NotImplementedError end |
#worker_lock(&_block) ⇒ Object
76 77 78 |
# File 'lib/process_balancer/base.rb', line 76 def worker_lock(&_block) raise NotImplementedError, 'Specify a locking driver via lock_driver :driver' end |