Class: TypeFusion::Processor
- Inherits:
-
Object
- Object
- TypeFusion::Processor
- Defined in:
- lib/type_fusion/processor.rb
Instance Method Summary collapse
- #enqueued_jobs ⇒ Object
-
#initialize(amount = 4) ⇒ Processor
constructor
A new instance of Processor.
- #process! ⇒ Object
- #should_run? ⇒ Boolean
- #start! ⇒ Object
- #started? ⇒ Boolean
- #stop! ⇒ Object
Constructor Details
#initialize(amount = 4) ⇒ Processor
Returns a new instance of Processor.
5 6 7 8 9 |
# File 'lib/type_fusion/processor.rb', line 5 def initialize(amount = 4) @amount = amount @servers = [] @started = false end |
Instance Method Details
#enqueued_jobs ⇒ Object
19 20 21 |
# File 'lib/type_fusion/processor.rb', line 19 def enqueued_jobs Litequeue.instance.count end |
#process! ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/type_fusion/processor.rb', line 38 def process! puts "[TypeFusion] Start processing of #{enqueued_jobs} samples using #{@amount} threads..." Signal.trap("INT") do puts "\n[TypeFusion] Stop processing of TypeFusion samples..." stop! end start! while should_run? puts "[TypeFusion] Remaining samples: #{Litequeue.instance.count}" sleep 1 end puts "[TypeFusion] Finished!" puts "[TypeFusion] Congratulations! You just contributed samples to the following gems and helped making the Ruby ecosystem better for the whole community! Thank you!\n" puts "- #{gems.join("\n- ")}" stop! end |
#should_run? ⇒ Boolean
11 12 13 |
# File 'lib/type_fusion/processor.rb', line 11 def should_run? enqueued_jobs.positive? end |
#start! ⇒ Object
31 32 33 34 35 36 |
# File 'lib/type_fusion/processor.rb', line 31 def start! @amount.times do @servers << Litejob::Server.new end @started = true end |
#started? ⇒ Boolean
15 16 17 |
# File 'lib/type_fusion/processor.rb', line 15 def started? @started end |
#stop! ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/type_fusion/processor.rb', line 23 def stop! @servers.each do |server| server.instance_variable_get(:@scheduler).context.kill end @servers = [] @started = false end |