Class: DataPipe::Job
- Inherits:
-
Object
- Object
- DataPipe::Job
- Defined in:
- lib/Jobs.rb
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
- #addError(e) ⇒ Object
- #call ⇒ Object
- #clearError ⇒ Object
-
#initialize(path) ⇒ Job
constructor
A new instance of Job.
- #run ⇒ Object
- #runNow ⇒ Object
- #setCron ⇒ Object
Constructor Details
#initialize(path) ⇒ Job
Returns a new instance of Job.
10 11 12 13 14 15 16 17 |
# File 'lib/Jobs.rb', line 10 def initialize( path ) @path = path @name = File.basename( path, ".dsl" ) @cronString = "" @errorList = Array.new self.setCron end |
Instance Attribute Details
#errorList ⇒ Object (readonly)
Returns the value of attribute errorList.
8 9 10 |
# File 'lib/Jobs.rb', line 8 def errorList @errorList end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/Jobs.rb', line 8 def name @name end |
#next ⇒ Object (readonly)
Returns the value of attribute next.
8 9 10 |
# File 'lib/Jobs.rb', line 8 def next @next end |
Instance Method Details
#addError(e) ⇒ Object
19 20 21 22 |
# File 'lib/Jobs.rb', line 19 def addError( e ) #Job Error -> Time, Exception Class Name, nsg, backtrace @errorList << "#{e.class.name}: #{e.}\n#{e.backtrace.join( "\n" )}" end |
#call ⇒ Object
41 42 43 |
# File 'lib/Jobs.rb', line 41 def call self.run if Time.now > @next end |
#clearError ⇒ Object
24 25 26 |
# File 'lib/Jobs.rb', line 24 def clearError @errorList = Array.new end |
#run ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/Jobs.rb', line 45 def run begin DataPipe.log "path: #{@path}", true DataPipe.log "dsl: #{@name}" load @path self.clearError rescue SystemExit, Interrupt raise rescue Exception => e # string = "#{e.class.name}: #{e.message}\n#{e.backtrace.join( "\n" )}" string = e. DataPipe.log_dsl @name, string self.addError( e ) end self.setCron @next = @cron.next(Time.now) end |
#runNow ⇒ Object
28 29 30 |
# File 'lib/Jobs.rb', line 28 def runNow @next = Time.now - 1 end |
#setCron ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/Jobs.rb', line 33 def setCron tmp = ENV["#{@name}_CRON"] ||= "0 0 * * *" return if tmp == @cronString @cronString = tmp @cron = CronParser.new(@cronString) end |