Class: Async::Runner::Job
- Inherits:
-
Object
- Object
- Async::Runner::Job
- Includes:
- Console
- Defined in:
- lib/async/runner/job.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #async(&block) ⇒ Object
- #before(container = nil, options = nil, &block) ⇒ Object
- #execute ⇒ Object
-
#initialize(file, **options) ⇒ Job
constructor
A new instance of Job.
- #intro ⇒ Object
- #job ⇒ Object
- #limit(limit) ⇒ Object
- #progress(total:) ⇒ Object
- #run(&block) ⇒ Object
- #setup(&block) ⇒ Object
Constructor Details
#initialize(file, **options) ⇒ Job
Returns a new instance of Job.
8 9 10 11 12 13 14 |
# File 'lib/async/runner/job.rb', line 8 def initialize(file, **) path = File.realpath(file) = = Async::Barrier.new @semaphore = Async::Semaphore.new([:jobs], parent: ) instance_eval File.read(path), path end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
6 7 8 |
# File 'lib/async/runner/job.rb', line 6 def block @block end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/async/runner/job.rb', line 6 def end |
Class Method Details
.to_s ⇒ Object
65 66 67 |
# File 'lib/async/runner/job.rb', line 65 def self.to_s "Runner" end |
Instance Method Details
#async(&block) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/async/runner/job.rb', line 45 def async(&block) @semaphore.async do block.call @progress&.increment end end |
#before(container = nil, options = nil, &block) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/async/runner/job.rb', line 16 def before(container=nil, =nil, &block) if block_given? @before_block = block else @before_block&.call(container, ) end end |
#execute ⇒ Object
32 33 34 35 |
# File 'lib/async/runner/job.rb', line 32 def execute @block.call(job) .wait end |
#intro ⇒ Object
60 61 62 63 |
# File 'lib/async/runner/job.rb', line 60 def intro type = [:container].to_s.capitalize Console.logger.info "=> Starting #{type} async containers" end |
#job ⇒ Object
24 25 26 |
# File 'lib/async/runner/job.rb', line 24 def job self end |
#limit(limit) ⇒ Object
37 38 39 |
# File 'lib/async/runner/job.rb', line 37 def limit(limit) @semaphore = Async::Semaphore.new(limit, parent: ) end |
#progress(total:) ⇒ Object
41 42 43 |
# File 'lib/async/runner/job.rb', line 41 def progress(total:) @progress = logger.progress("jobs", total) end |
#run(&block) ⇒ Object
28 29 30 |
# File 'lib/async/runner/job.rb', line 28 def run(&block) @block = block end |
#setup(&block) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/async/runner/job.rb', line 52 def setup(&block) if block_given? @setup_block = block else @setup_block&.call job end end |