Class: Whenever::JobList

Inherits:
Object
  • Object
show all
Defined in:
lib/job_list.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ JobList

Returns a new instance of JobList.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/job_list.rb', line 4

def initialize(options)
  @jobs = Hash.new
  @env  = Hash.new
  
  @environment = options[:environment]
  
  config = case options
    when String then options
    when Hash
      if options[:string]
        options[:string]
      elsif options[:file]
        File.read(options[:file])
      end
  end

  eval(config)
end

Instance Method Details

#command(task, options = {}) ⇒ Object



38
39
40
41
42
43
# File 'lib/job_list.rb', line 38

def command(task, options = {})
  options[:cron_log] ||= @cron_log unless options[:cron_log] === false
  options[:class]    ||= Whenever::Job::Default
  @jobs[@current_time_scope] ||= []
  @jobs[@current_time_scope] << options[:class].new(@options.merge(:task => task).merge(options))
end

#env(variable, value) ⇒ Object



28
29
30
# File 'lib/job_list.rb', line 28

def env(variable, value)
  @env[variable.to_s] = value
end

#every(frequency, options = {}) ⇒ Object



32
33
34
35
36
# File 'lib/job_list.rb', line 32

def every(frequency, options = {})
  @current_time_scope = frequency
  @options = options
  yield
end

#generate_cron_outputObject



57
58
59
# File 'lib/job_list.rb', line 57

def generate_cron_output
  [environment_variables, cron_jobs].compact.join
end

#rake(task, options = {}) ⇒ Object



51
52
53
54
55
# File 'lib/job_list.rb', line 51

def rake(task, options = {})
  options.reverse_merge!(:environment => @environment, :path => @path)
  options[:class] = Whenever::Job::RakeTask
  command(task, options)
end

#runner(task, options = {}) ⇒ Object



45
46
47
48
49
# File 'lib/job_list.rb', line 45

def runner(task, options = {})
  options.reverse_merge!(:environment => @environment, :path => @path)
  options[:class] = Whenever::Job::Runner
  command(task, options)
end

#set(variable, value) ⇒ Object



23
24
25
26
# File 'lib/job_list.rb', line 23

def set(variable, value)
  instance_variable_set("@#{variable}".to_sym, value)
  self.class.send(:attr_reader, variable.to_sym)
end