Module: Eye::Process::Scheduler
- Included in:
- ChildProcess, Group, Eye::Process
- Defined in:
- lib/eye/process/scheduler.rb
Instance Attribute Summary collapse
-
#current_scheduled_command ⇒ Object
Returns the value of attribute current_scheduled_command.
-
#last_scheduled_at ⇒ Object
Returns the value of attribute last_scheduled_at.
-
#last_scheduled_command ⇒ Object
Returns the value of attribute last_scheduled_command.
-
#last_scheduled_reason ⇒ Object
Returns the value of attribute last_scheduled_reason.
Class Method Summary collapse
Instance Method Summary collapse
-
#schedule(command, *args, &block) ⇒ Object
ex: schedule :update_config, config, “reason: update_config”.
- #schedule_history ⇒ Object
- #schedule_in(interval, command, *args, &block) ⇒ Object
- #scheduled_action(command, h = {}, &block) ⇒ Object
- #scheduler_actions_list ⇒ Object
- #scheduler_clear_pending_list ⇒ Object
- #scheduler_freeze ⇒ Object
- #scheduler_freeze? ⇒ Boolean
- #scheduler_unfreeze ⇒ Object
Instance Attribute Details
#current_scheduled_command ⇒ Object
Returns the value of attribute current_scheduled_command.
74 75 76 |
# File 'lib/eye/process/scheduler.rb', line 74 def current_scheduled_command @current_scheduled_command end |
#last_scheduled_at ⇒ Object
Returns the value of attribute last_scheduled_at.
75 76 77 |
# File 'lib/eye/process/scheduler.rb', line 75 def last_scheduled_at @last_scheduled_at end |
#last_scheduled_command ⇒ Object
Returns the value of attribute last_scheduled_command.
75 76 77 |
# File 'lib/eye/process/scheduler.rb', line 75 def last_scheduled_command @last_scheduled_command end |
#last_scheduled_reason ⇒ Object
Returns the value of attribute last_scheduled_reason.
75 76 77 |
# File 'lib/eye/process/scheduler.rb', line 75 def last_scheduled_reason @last_scheduled_reason end |
Class Method Details
.included(base) ⇒ Object
70 71 72 |
# File 'lib/eye/process/scheduler.rb', line 70 def self.included(base) base.finalizer :remove_scheduler end |
Instance Method Details
#schedule(command, *args, &block) ⇒ Object
ex: schedule :update_config, config, “reason: update_config”
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/eye/process/scheduler.rb', line 4 def schedule(command, *args, &block) if scheduler.alive? if scheduler_freeze? warn ":#{command} ignoring to schedule, because scheduler is freeze" return end unless self.respond_to?(command, true) warn ":#{command} scheduling is unsupported" return end reason = if args.present? && args[-1].kind_of?(Eye::Reason) args.pop end info "schedule :#{command} #{reason ? "(reason: #{reason})" : nil}" if reason.class == Eye::Reason # for auto reasons # skip already running commands and all in chain scheduler.add_wo_dups_current(:scheduled_action, command, {:args => args, :reason => reason}, &block) else # for manual, or without reason # skip only for last in chain scheduler.add_wo_dups(:scheduled_action, command, {:args => args, :reason => reason}, &block) end end end |
#schedule_history ⇒ Object
77 78 79 |
# File 'lib/eye/process/scheduler.rb', line 77 def schedule_history @schedule_history ||= Eye::Process::StatesHistory.new(50) end |
#schedule_in(interval, command, *args, &block) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/eye/process/scheduler.rb', line 34 def schedule_in(interval, command, *args, &block) debug { "schedule_in #{interval} :#{command} #{args}" } after(interval.to_f) do debug { "scheduled_in #{interval} :#{command} #{args}" } schedule(command, *args, &block) end end |
#scheduled_action(command, h = {}, &block) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/eye/process/scheduler.rb', line 42 def scheduled_action(command, h = {}, &block) reason = h.delete(:reason) info "=> #{command} #{h[:args].present? ? "#{h[:args]*',' }" : nil} #{reason ? "(reason: #{reason})" : nil}" @current_scheduled_command = command @last_scheduled_command = command @last_scheduled_reason = reason @last_scheduled_at = Time.now send(command, *h[:args], &block) @current_scheduled_command = nil info "<= #{command}" schedule_history.push(command, reason, @last_scheduled_at.to_i) if parent = self.try(:parent) parent.schedule_history.push("#{command}_child", reason, @last_scheduled_at.to_i) end end |
#scheduler_actions_list ⇒ Object
62 63 64 |
# File 'lib/eye/process/scheduler.rb', line 62 def scheduler_actions_list scheduler.list.map{|c| c[:args].first rescue nil }.compact end |
#scheduler_clear_pending_list ⇒ Object
66 67 68 |
# File 'lib/eye/process/scheduler.rb', line 66 def scheduler_clear_pending_list scheduler.clear_pending_list end |
#scheduler_freeze ⇒ Object
81 82 83 |
# File 'lib/eye/process/scheduler.rb', line 81 def scheduler_freeze @scheduler_freeze = true end |
#scheduler_freeze? ⇒ Boolean
89 90 91 |
# File 'lib/eye/process/scheduler.rb', line 89 def scheduler_freeze? @scheduler_freeze end |
#scheduler_unfreeze ⇒ Object
85 86 87 |
# File 'lib/eye/process/scheduler.rb', line 85 def scheduler_unfreeze @scheduler_freeze = nil end |