module Eye::Process::Scheduler
Public Instance Methods
ensure_scheduler_process()
click to toggle source
# File lib/eye/process/scheduler.rb, line 115 def ensure_scheduler_process unless @scheduler_running @scheduler_running = true async.scheduler_run end end
equal_action_call?(call1, call2)
click to toggle source
# File lib/eye/process/scheduler.rb, line 98 def equal_action_call?(call1, call2) call1 && call2 && (call1[:command] == call2[:command]) && (call1[:args] == call2[:args]) && (call1[:block] == call2[:block]) end
filter_call(call)
click to toggle source
# File lib/eye/process/scheduler.rb, line 90 def filter_call(call) # for auto reasons, compare call with current @scheduled_call return false if call[:by] != :user && equal_action_call?(@scheduled_call, call) # check any equal call in queue scheduler_calls scheduler_calls.none? { |c| equal_action_call?(c, call) } end
internal_schedule(call)
click to toggle source
# File lib/eye/process/scheduler.rb, line 34 def internal_schedule(call) if interval = call[:in] debug { "schedule_in #{interval} :#{call[:command]}" } after(interval.to_f) do debug { "scheduled_in #{interval} :#{call[:command]}" } call[:in] = nil internal_schedule(call) end return end call[:at] ||= Time.now.to_i command = call[:command] @scheduler_freeze = false if call[:freeze] == false if @scheduler_freeze warn ":#{command} ignoring to schedule, because scheduler is freezed" return end unless self.respond_to?(command, true) warn ":#{command} scheduling is unsupported" return end if filter_call(call) info "schedule :#{command} (#{reason_from_call(call)})" scheduler_add(call) else info "not scheduled: #{command} (#{reason_from_call(call)})" end @scheduler_freeze = true if call[:freeze] == true end
schedule(*args)
click to toggle source
2 Forms of schedule: schedule command: 'bla', args: [1, 2, 3] schedule :bla, 1, 2, 3
# File lib/eye/process/scheduler.rb, line 26 def schedule(*args) if args[0].is_a?(Hash) internal_schedule(args[0]) else internal_schedule(command: args[0], args: args[1..-1]) end end
scheduler_add(call)
click to toggle source
# File lib/eye/process/scheduler.rb, line 110 def scheduler_add(call) scheduler_calls << call ensure_scheduler_process end
scheduler_calls()
click to toggle source
# File lib/eye/process/scheduler.rb, line 102 def scheduler_calls @scheduler_calls ||= [] end
scheduler_clear_pending_list()
click to toggle source
# File lib/eye/process/scheduler.rb, line 135 def scheduler_clear_pending_list scheduler_calls.clear end
scheduler_commands_list()
click to toggle source
# File lib/eye/process/scheduler.rb, line 131 def scheduler_commands_list scheduler_calls.map { |c| c[:command] } end
scheduler_consume(call)
click to toggle source
# File lib/eye/process/scheduler.rb, line 70 def scheduler_consume(call) args = call[:args] reason_str = reason_from_call(call) info "=> #{call[:command]} #{args.present? ? args.join(',') : nil} (#{reason_str})" send(call[:command], *args, &call[:block]) history_cmd = is_a?(Eye::ChildProcess) ? "#{call[:command]}_child" : call[:command] scheduler_history.push(history_cmd, reason_str, call[:at]) rescue Object => ex raise(ex) if ex.class == Celluloid::TaskTerminated log_ex(ex) ensure # signaling to waiter call[:signal].try :signal info "<= #{call[:command]}" end
scheduler_current_command()
click to toggle source
# File lib/eye/process/scheduler.rb, line 147 def scheduler_current_command @scheduled_call.try :[], :command end
scheduler_history()
click to toggle source
# File lib/eye/process/scheduler.rb, line 106 def scheduler_history @scheduler_history ||= Eye::Process::StatesHistory.new(50) end
scheduler_last_command()
click to toggle source
# File lib/eye/process/scheduler.rb, line 139 def scheduler_last_command @last_scheduled_call.try :[], :command end
scheduler_last_reason()
click to toggle source
# File lib/eye/process/scheduler.rb, line 143 def scheduler_last_reason reason_from_call(@last_scheduled_call) end
scheduler_run()
click to toggle source
# File lib/eye/process/scheduler.rb, line 122 def scheduler_run while @scheduled_call = scheduler_calls.shift @scheduler_running = true @last_scheduled_call = @scheduled_call scheduler_consume(@scheduled_call) end @scheduler_running = false end
send_call(call)
click to toggle source
:update_config, :start, :stop, :restart, :unmonitor, :monitor, :break_chain, :delete, :signal, :user_command
# File lib/eye/process/scheduler.rb, line 14 def send_call(call) user_schedule(call) end
user_schedule(call)
click to toggle source
# File lib/eye/process/scheduler.rb, line 18 def user_schedule(call) call[:by] ||= :user internal_schedule(call) end
Private Instance Methods
reason_from_call(call)
click to toggle source
# File lib/eye/process/scheduler.rb, line 153 def reason_from_call(call) return unless call if msg = call[:reason] msg.to_s elsif call[:by] "#{call[:command]} by #{call[:by]}" end end