class DataPipe2::Job

Hold a single job definition

Attributes

errorList[R]
name[R]
next[R]

Public Class Methods

new(path) click to toggle source
# File lib/jobs.rb, line 9
def initialize(path)
  @path = path
  @name = File.basename(path, '.dsl')
  @cron_string = ''

  @error_list = []
  set_cron
end

Public Instance Methods

add_error(e) click to toggle source

Job Error -> Time, Exception Class Name, nsg, backtrace

# File lib/jobs.rb, line 19
def add_error(e)
  @error_list << "#{e.class.name}: #{e.message}\n#{e.backtrace.join("\n")}"
end
call() click to toggle source
# File lib/jobs.rb, line 39
def call
  run if Time.now > @next
end
clear_error() click to toggle source
# File lib/jobs.rb, line 23
def clear_error
  @error_list = []
end
run() click to toggle source
# File lib/jobs.rb, line 43
def run
  begin
    DataPipe2.log "path: #{@path}", true
    DataPipe2.log "dsl: #{@name}"
    load @path
    clear_error
  rescue SystemExit, Interrupt
    raise
  rescue StandardError => e
    string = e.message
    p e.backtrace
    DataPipe2.log_dsl @name, string
    add_error(e)
  end

  set_cron
  @next = @cron.next(Time.now)
end
run_now() click to toggle source
# File lib/jobs.rb, line 27
def run_now
  @next = Time.now - 1
end
set_cron() click to toggle source
# File lib/jobs.rb, line 31
def set_cron
  tmp = ENV["#{@name}_CRON"] ||= '0 0 * * *'
  return if tmp == @cron_string

  @cron_string = tmp
  @cron = CronParser.new(@cron_string)
end