Class: DataPipe2::Job
- Inherits:
-
Object
- Object
- DataPipe2::Job
- Defined in:
- lib/jobs.rb
Overview
Hold a single job definition
Instance Attribute Summary collapse
-
#errorList ⇒ Object
readonly
Returns the value of attribute errorList.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#next ⇒ Object
readonly
Returns the value of attribute next.
Instance Method Summary collapse
-
#add_error(e) ⇒ Object
Job Error -> Time, Exception Class Name, nsg, backtrace.
- #call ⇒ Object
- #clear_error ⇒ Object
-
#initialize(path) ⇒ Job
constructor
A new instance of Job.
- #run ⇒ Object
- #run_now ⇒ Object
- #set_cron ⇒ Object
Constructor Details
#initialize(path) ⇒ Job
Returns a new instance of Job.
9 10 11 12 13 14 15 16 |
# File 'lib/jobs.rb', line 9 def initialize(path) @path = path @name = File.basename(path, '.dsl') @cron_string = '' @error_list = [] set_cron end |
Instance Attribute Details
#errorList ⇒ Object (readonly)
Returns the value of attribute errorList.
7 8 9 |
# File 'lib/jobs.rb', line 7 def errorList @errorList end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/jobs.rb', line 7 def name @name end |
#next ⇒ Object (readonly)
Returns the value of attribute next.
7 8 9 |
# File 'lib/jobs.rb', line 7 def next @next end |
Instance Method Details
#add_error(e) ⇒ Object
Job Error -> Time, Exception Class Name, nsg, backtrace
19 20 21 |
# File 'lib/jobs.rb', line 19 def add_error(e) @error_list << "#{e.class.name}: #{e.message}\n#{e.backtrace.join("\n")}" end |
#call ⇒ Object
39 40 41 |
# File 'lib/jobs.rb', line 39 def call run if Time.now > @next end |
#clear_error ⇒ Object
23 24 25 |
# File 'lib/jobs.rb', line 23 def clear_error @error_list = [] end |
#run ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# 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. p e.backtrace DataPipe2.log_dsl @name, string add_error(e) end set_cron @next = @cron.next(Time.now) end |
#run_now ⇒ Object
27 28 29 |
# File 'lib/jobs.rb', line 27 def run_now @next = Time.now - 1 end |
#set_cron ⇒ Object
31 32 33 34 35 36 37 |
# 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 |