module Eye::Process::Scheduler
Attributes
current_scheduled_command[RW]
last_scheduled_at[RW]
last_scheduled_command[RW]
last_scheduled_reason[RW]
Public Class Methods
included(base)
click to toggle source
# File lib/eye/process/scheduler.rb, line 61 def self.included(base) base.finalizer :remove_scheduler end
Public Instance Methods
schedule(command, *args, &block)
click to toggle source
ex: schedule :update_config, config, “reason: update_config”
# File lib/eye/process/scheduler.rb, line 4 def schedule(command, *args, &block) if scheduler.alive? 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()
click to toggle source
# File lib/eye/process/scheduler.rb, line 68 def schedule_history @schedule_history ||= Eye::Process::StatesHistory.new(50) end
schedule_in(interval, command, *args, &block)
click to toggle source
# File lib/eye/process/scheduler.rb, line 29 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)
click to toggle source
# File lib/eye/process/scheduler.rb, line 37 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) end
scheduler_actions_list()
click to toggle source
# File lib/eye/process/scheduler.rb, line 53 def scheduler_actions_list scheduler.list.map{|c| c[:args].first rescue nil }.compact end
scheduler_clear_pending_list()
click to toggle source
# File lib/eye/process/scheduler.rb, line 57 def scheduler_clear_pending_list scheduler.clear_pending_list end
Private Instance Methods
remove_scheduler()
click to toggle source
# File lib/eye/process/scheduler.rb, line 74 def remove_scheduler @scheduler.terminate if @scheduler && @scheduler.alive? end
scheduler()
click to toggle source
# File lib/eye/process/scheduler.rb, line 78 def scheduler @scheduler ||= Eye::Utils::CelluloidChain.new(current_actor) end