Method: Eye::Process::Scheduler#schedule

Defined in:
lib/eye/process/scheduler.rb

#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
# File 'lib/eye/process/scheduler.rb', line 4

def schedule(command, *args, &block)
  if scheduler.alive?
    unless self.respond_to?(command, true)
      warn "object not support :#{command} to schedule"
      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