Class: Blender::Scheduler
- Inherits:
-
Object
- Object
- Blender::Scheduler
- Includes:
- Lock, SchedulerDSL
- Defined in:
- lib/blender/scheduler.rb
Instance Attribute Summary collapse
-
#events ⇒ Object
readonly
Returns the value of attribute events.
-
#lock_properties ⇒ Object
readonly
Returns the value of attribute lock_properties.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#scheduling_strategy ⇒ Object
readonly
Returns the value of attribute scheduling_strategy.
-
#tasks ⇒ Object
readonly
Returns the value of attribute tasks.
Instance Method Summary collapse
- #concurrent_run(jobs) ⇒ Object
- #default_metadata ⇒ Object
-
#initialize(name, tasks = [], options = {}) ⇒ Scheduler
constructor
A new instance of Scheduler.
- #run ⇒ Object
- #run_job(job) ⇒ Object
- #serial_run(jobs) ⇒ Object
Methods included from SchedulerDSL
#add_handler, #append_task, #ask, #build_task, #concurrency, #config, #driver, #ignore_failure, #lock, #lock_options, #log_level, #members, #on, #ruby_task, #scp_download, #scp_upload, #shell_task, #ssh_task, #strategy
Methods included from Discovery
#build_discovery, #old_search, #search, #search_with_config
Methods included from Utils::Refinements
Constructor Details
#initialize(name, tasks = [], options = {}) ⇒ Scheduler
Returns a new instance of Scheduler.
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/blender/scheduler.rb', line 41 def initialize(name, tasks = [], = {}) @name = name @tasks = tasks @events = Blender::EventDispatcher.new unless .delete(:no_doc) events.register(Blender::Handlers::Doc.new) end @metadata = .merge() @scheduling_strategy = nil @lock_properties = {driver: nil, driver_options: {}} end |
Instance Attribute Details
#events ⇒ Object (readonly)
Returns the value of attribute events.
38 39 40 |
# File 'lib/blender/scheduler.rb', line 38 def events @events end |
#lock_properties ⇒ Object (readonly)
Returns the value of attribute lock_properties.
39 40 41 |
# File 'lib/blender/scheduler.rb', line 39 def lock_properties @lock_properties end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
36 37 38 |
# File 'lib/blender/scheduler.rb', line 36 def @metadata end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
36 37 38 |
# File 'lib/blender/scheduler.rb', line 36 def name @name end |
#scheduling_strategy ⇒ Object (readonly)
Returns the value of attribute scheduling_strategy.
37 38 39 |
# File 'lib/blender/scheduler.rb', line 37 def scheduling_strategy @scheduling_strategy end |
#tasks ⇒ Object (readonly)
Returns the value of attribute tasks.
38 39 40 |
# File 'lib/blender/scheduler.rb', line 38 def tasks @tasks end |
Instance Method Details
#concurrent_run(jobs) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/blender/scheduler.rb', line 80 def concurrent_run(jobs) c = [:concurrency] Log.debug("Invoking concurrent run with concurrency:#{c}") pool = Utils::ThreadPool.new(c) jobs.each do |job| pool.add_job do run_job(job) end end pool.run_till_done end |
#default_metadata ⇒ Object
106 107 108 109 110 111 112 113 |
# File 'lib/blender/scheduler.rb', line 106 def { ignore_failure: false, concurrency: 0, handlers: [], members: [] } end |
#run ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/blender/scheduler.rb', line 53 def run @scheduling_strategy ||= SchedulingStrategy::Default.new events.run_started(self) events.job_computation_started(scheduling_strategy) jobs = scheduling_strategy.compute_jobs(@tasks) events.job_computation_finished(self, jobs) lock do if [:concurrency] > 1 concurrent_run(jobs) else serial_run(jobs) end events.run_finished(self) jobs end rescue StandardError => e events.run_failed(self, e) raise e end |
#run_job(job) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/blender/scheduler.rb', line 92 def run_job(job) events.job_started(job) Log.debug("Running job #{job.name}") job.run events.job_finished(job) rescue StandardError => e events.job_failed(job, e) if [:ignore_failure] Log.warn("Exception: #{e.inspect} was suppressed, ignoring failure") else raise e end end |
#serial_run(jobs) ⇒ Object
73 74 75 76 77 78 |
# File 'lib/blender/scheduler.rb', line 73 def serial_run(jobs) Log.debug('Invoking serial run') jobs.each do |job| run_job(job) end end |