Class: Async::Cron::Scheduler
- Inherits:
-
Object
- Object
- Async::Cron::Scheduler
- Defined in:
- lib/async/cron/scheduler.rb
Defined Under Namespace
Classes: Loader
Constant Summary collapse
- PATH =
"config/async/cron/scheduler.rb"
Instance Attribute Summary collapse
-
#schedules ⇒ Object
readonly
Returns the value of attribute schedules.
Class Method Summary collapse
Instance Method Summary collapse
- #add(schedule, &block) ⇒ Object
-
#initialize ⇒ Scheduler
constructor
A new instance of Scheduler.
- #run ⇒ Object
Constructor Details
#initialize ⇒ Scheduler
61 62 63 |
# File 'lib/async/cron/scheduler.rb', line 61 def initialize @schedules = Hash.new.compare_by_identity end |
Instance Attribute Details
#schedules ⇒ Object (readonly)
Returns the value of attribute schedules.
65 66 67 |
# File 'lib/async/cron/scheduler.rb', line 65 def schedules @schedules end |
Class Method Details
.load(root = Dir.pwd) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/async/cron/scheduler.rb', line 44 def self.load(root = Dir.pwd) path = ::File.join(root, PATH) if ::File.exist?(path) return self.load_file(path) end end |
.load_file(path) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/async/cron/scheduler.rb', line 52 def self.load_file(path) scheduler = self.new loader = Loader.new(scheduler) loader.instance_eval(::File.read(path), path) return scheduler end |
Instance Method Details
#add(schedule, &block) ⇒ Object
67 68 69 |
# File 'lib/async/cron/scheduler.rb', line 67 def add(schedule, &block) @schedules[schedule] = block end |
#run ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/async/cron/scheduler.rb', line 71 def run Sync do = Async::Barrier.new @schedules.each do |schedule, block| .async do schedule.run(&block) end end .wait end end |