Class: Remon::Scheduler
- Inherits:
-
Object
- Object
- Remon::Scheduler
- Includes:
- Logger
- Defined in:
- lib/remon/scheduler.rb
Instance Attribute Summary collapse
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
Instance Method Summary collapse
-
#initialize(schedule, queue:, scheduler_offset: 0) ⇒ Scheduler
constructor
A new instance of Scheduler.
- #run(n = :inf, show_progress: true) ⇒ Object
- #schedule_tasks(time) ⇒ Object
- #ticker(n, show_progress = false) ⇒ Object
Methods included from Logger
Constructor Details
#initialize(schedule, queue:, scheduler_offset: 0) ⇒ Scheduler
Returns a new instance of Scheduler.
10 11 12 13 14 15 16 |
# File 'lib/remon/scheduler.rb', line 10 def initialize(schedule, queue:, scheduler_offset: 0) @schedule = schedule @queue = queue @scheduler_pipeline = {} @scheduler_offset = scheduler_offset validate_schedule end |
Instance Attribute Details
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
8 9 10 |
# File 'lib/remon/scheduler.rb', line 8 def queue @queue end |
Instance Method Details
#run(n = :inf, show_progress: true) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/remon/scheduler.rb', line 18 def run(n = :inf, show_progress: true) logger.debug "starting scheduler" ticker(n, show_progress) do |t| schedule_tasks (t + @scheduler_offset) end end |
#schedule_tasks(time) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/remon/scheduler.rb', line 25 def schedule_tasks(time) task_groups = keys.select { |i| time % i[:interval] == 0} task_groups.each do |tg| pipeline_task_group tg, time end enqueue_tasks(time) end |
#ticker(n, show_progress = false) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/remon/scheduler.rb', line 33 def ticker(n, show_progress = false) t = Time.now.to_i case n when Integer n.times do |i| puts i if show_progress yield t t = t + 1 sleep_till t end else loop do yield t t = t + 1 sleep_till t end end end |