Class: JobLog
- Inherits:
-
Object
- Object
- JobLog
- Defined in:
- lib/job_log.rb
Instance Method Summary collapse
-
#initialize(dxfilepath = 'joblog.xml', host: 'sps2', port: 59100) ⇒ JobLog
constructor
A new instance of JobLog.
- #listen ⇒ Object
Constructor Details
#initialize(dxfilepath = 'joblog.xml', host: 'sps2', port: 59100) ⇒ JobLog
Returns a new instance of JobLog.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/job_log.rb', line 11 def initialize(dxfilepath='joblog.xml', host: 'sps2', port: 59100) @dxfilepath = dxfilepath @sps = SPSSub.new host: host, port: port @dx = if File.exists? dxfilepath then Dynarex.new(dxfilepath) else Dynarex.new 'jobs/job(title, desc, started, ended, status, tags)' end end |
Instance Method Details
#listen ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/job_log.rb', line 23 def listen topics = %w(started done aborted).map {|x| "log/+/#{x}/+"}.join(' | ') @sps.subscribe(topic: topics) do |msg, topic| title = topic[/(?<=log\/)\w+/] case topic when /\/started\// desc, = msg.split(/(?= +#)/,2) = .scan(/(?<=#)\w+/).join ' ' @dx.create title: title, started: Time.now.to_s, desc: desc, tags: when /\/done\// r = @dx.find_by_title title r.ended = Time.now.to_s if r r.status = 'success' when /\/aborted\// r = @dx.find_by_title title r.ended = Time.now.to_s if r r.status = msg end # write the entry to file @dx.save @dxfilepath end end |