2012-12-11 10:42:15 +00:00
|
|
|
module AbfWorker
|
2016-05-28 19:21:02 +01:00
|
|
|
class BaseObserver < BaseActiveRecordJob
|
|
|
|
include Sidekiq::Worker
|
|
|
|
|
2013-02-06 11:18:29 +00:00
|
|
|
COMPLETED = 0
|
|
|
|
FAILED = 1
|
|
|
|
PENDING = 2
|
|
|
|
STARTED = 3
|
|
|
|
CANCELED = 4
|
|
|
|
TESTS_FAILED = 5
|
2012-12-11 11:47:32 +00:00
|
|
|
|
2013-02-05 18:49:26 +00:00
|
|
|
attr_accessor :status, :options
|
|
|
|
|
2016-05-28 19:21:02 +01:00
|
|
|
def perform(options)
|
2014-05-29 21:05:13 +01:00
|
|
|
@status = options['status'].to_i
|
|
|
|
@options = options
|
2016-05-28 19:21:02 +01:00
|
|
|
real_perform
|
2013-02-05 18:49:26 +00:00
|
|
|
end
|
|
|
|
|
2016-05-28 19:21:02 +01:00
|
|
|
def real_perform
|
2013-02-05 18:49:26 +00:00
|
|
|
raise NotImplementedError, "You should implement this method"
|
|
|
|
end
|
|
|
|
|
2013-02-06 10:14:36 +00:00
|
|
|
protected
|
|
|
|
|
|
|
|
def subject
|
2014-05-29 21:05:13 +01:00
|
|
|
@subject ||= @subject_class.find(options['id'])
|
2013-02-06 10:14:36 +00:00
|
|
|
end
|
|
|
|
|
2013-02-05 18:49:26 +00:00
|
|
|
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)
|
2012-12-12 12:32:47 +00:00
|
|
|
end
|
|
|
|
|
2013-02-06 15:28:03 +00:00
|
|
|
def sort_results_and_save(results, item = subject)
|
2014-05-29 21:41:15 +01:00
|
|
|
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)
|
2012-12-11 11:47:32 +00:00
|
|
|
end
|
|
|
|
|
2012-12-11 10:42:15 +00:00
|
|
|
end
|
|
|
|
end
|