Class: DataPipe::Job

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#errorListObject (readonly)

Returns the value of attribute errorList.



8
9
10
# File 'lib/Jobs.rb', line 8

def errorList
  @errorList
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/Jobs.rb', line 8

def name
  @name
end

#nextObject (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.message}\n#{e.backtrace.join( "\n" )}"
end

#callObject



41
42
43
# File 'lib/Jobs.rb', line 41

def call
	self.run if Time.now > @next
end

#clearErrorObject



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

def clearError
	@errorList = Array.new
end

#runObject



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.message
           DataPipe.log_dsl @name, string
	self.addError( e )
       end
       
	self.setCron 
	@next = @cron.next(Time.now)
end

#runNowObject



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

def runNow
	@next = Time.now - 1
end

#setCronObject



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