Class: ProconBypassMan::Worker
- Inherits:
-
Object
- Object
- ProconBypassMan::Worker
- Defined in:
- lib/procon_bypass_man/worker.rb
Instance Attribute Summary collapse
-
#pid ⇒ Object
Returns the value of attribute pid.
Class Method Summary collapse
Instance Method Summary collapse
- #run ⇒ Worker
-
#shutdown ⇒ Object
重要な非同期ジョブは存在しないのでqueueが捌けるのを待たずにkill.
- #work(job_class:, args:) ⇒ Object
Instance Attribute Details
#pid ⇒ Object
Returns the value of attribute pid.
3 4 5 |
# File 'lib/procon_bypass_man/worker.rb', line 3 def pid @pid end |
Class Method Details
.run ⇒ Object
5 6 7 |
# File 'lib/procon_bypass_man/worker.rb', line 5 def self.run new.run end |
Instance Method Details
#run ⇒ Worker
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/procon_bypass_man/worker.rb', line 10 def run return self if @thread @thread = Thread.new do while(item = ProconBypassMan::Background::JobQueue.pop) # プロセスを越えるので文字列になっている. evalしてクラスにする work(job_class: eval(item[:job_class]), args: item[:args]) sleep(0.2) # busy loopしないように end end return self end |
#shutdown ⇒ Object
重要な非同期ジョブは存在しないのでqueueが捌けるのを待たずにkill
36 37 38 |
# File 'lib/procon_bypass_man/worker.rb', line 36 def shutdown @thread&.kill end |
#work(job_class:, args:) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/procon_bypass_man/worker.rb', line 23 def work(job_class: , args: ) begin job_class.perform(*args) rescue => e ProconBypassMan.logger.error(e) if job_class.respond_to?(:re_enqueue_if_failed) && job_class.re_enqueue_if_failed job_class.perform_async(args) ProconBypassMan.logger.error("エラーが起きたので#{job_class}を積み直しました。") end end end |