rosa-build/app/jobs/abf_worker/base_observer.rb

42 lines
988 B
Ruby
Raw Normal View History

module AbfWorker
2012-12-11 15:25:25 +00:00
class BaseObserver
2013-02-06 11:18:29 +00:00
COMPLETED = 0
FAILED = 1
PENDING = 2
STARTED = 3
CANCELED = 4
TESTS_FAILED = 5
attr_accessor :status, :options
def initialize(options, subject_class)
2014-05-29 21:05:13 +01:00
@status = options['status'].to_i
@options = options
@subject_class = subject_class
end
def perform
raise NotImplementedError, "You should implement this method"
end
protected
def subject
2014-05-29 21:05:13 +01:00
@subject ||= @subject_class.find(options['id'])
end
def update_results
2014-05-29 21:05:13 +01:00
now = Time.zone.now.to_i
results = options['results'] || []
results.each{ |r| r['timestamp'] = now }
results += subject.results || []
sort_results_and_save(results)
end
def sort_results_and_save(results, item = subject)
item.results = results.sort_by{ |r| [r['timestamp'].to_s, r['file_name'].to_s] }
2014-01-21 04:51:49 +00:00
item.save(validate: false)
end
end
end