Class: Whenever::JobList
- Inherits:
-
Object
- Object
- Whenever::JobList
- Defined in:
- lib/whenever/job_list.rb
Instance Method Summary collapse
- #cron(frequency, options = {}) ⇒ Object
- #env(variable, value) ⇒ Object
- #every(frequency, options = {}) ⇒ Object
- #generate_cron_output ⇒ Object
-
#initialize(options) ⇒ JobList
constructor
A new instance of JobList.
- #job_type(name, template) ⇒ Object
- #set(variable, value) ⇒ Object
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 22 23 24 25 |
# File 'lib/whenever/job_list.rb', line 4 def initialize() @jobs, @env, @set_variables = {}, {}, {} case when String config = when Hash config = if [:string] [:string] elsif [:file] File.read([:file]) end pre_set([:set]) end # Load all job type files. Dir["#{File.(File.dirname(__FILE__))}/job_types/*.rb"].each do |file| eval(File.read(file)) end eval(config) end |
Instance Method Details
#cron(frequency, options = {}) ⇒ Object
45 46 47 48 49 |
# File 'lib/whenever/job_list.rb', line 45 def cron(frequency, = {}) @current_time_scope = frequency @options = .merge(:raw_syntex => true) yield end |
#env(variable, value) ⇒ Object
35 36 37 |
# File 'lib/whenever/job_list.rb', line 35 def env(variable, value) @env[variable.to_s] = value end |
#every(frequency, options = {}) ⇒ Object
39 40 41 42 43 |
# File 'lib/whenever/job_list.rb', line 39 def every(frequency, = {}) @current_time_scope = frequency @options = yield end |
#generate_cron_output ⇒ Object
68 69 70 71 72 |
# File 'lib/whenever/job_list.rb', line 68 def generate_cron_output set_path_environment_variable [environment_variables, cron_jobs].compact.join end |
#job_type(name, template) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/whenever/job_list.rb', line 51 def job_type(name, template) class_eval do define_method(name) do |task, *args| = { :task => task, :template => template } .merge!(args[0]) if args[0].is_a? Hash # :cron_log was an old option for output redirection, it remains for backwards compatibility [:output] = ([:cron_log] || @cron_log) if defined?(@cron_log) || .has_key?(:cron_log) # :output is the newer, more flexible option. [:output] = @output if defined?(@output) && !.has_key?(:output) @jobs[@current_time_scope] ||= [] @jobs[@current_time_scope] << Whenever::Job.new(@options.merge(@set_variables).merge()) end end end |
#set(variable, value) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/whenever/job_list.rb', line 27 def set(variable, value) return if instance_variable_defined?("@#{variable}".to_sym) instance_variable_set("@#{variable}".to_sym, value) self.class.send(:attr_reader, variable.to_sym) @set_variables[variable] = value end |