2012-12-06 14:41:24 +00:00
|
|
|
module AbfWorker
|
|
|
|
module ModelHelper
|
|
|
|
# In model which contains this helper should be:
|
|
|
|
# - #abf_worker_args
|
2012-12-06 19:18:28 +00:00
|
|
|
# - #build_canceled
|
2012-12-06 14:41:24 +00:00
|
|
|
|
|
|
|
def abf_worker_log
|
2012-12-28 14:00:37 +00:00
|
|
|
Resque.redis.get(service_queue) || I18n.t('layout.build_lists.log.not_available')
|
2012-12-06 14:41:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def add_job_to_abf_worker_queue
|
|
|
|
Resque.push(
|
2012-12-28 14:00:37 +00:00
|
|
|
worker_queue_with_priority,
|
2012-12-06 14:41:24 +00:00
|
|
|
'class' => worker_queue_class,
|
|
|
|
'args' => [abf_worker_args]
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def cancel_job
|
|
|
|
deleted = Resque::Job.destroy(
|
2012-12-28 14:00:37 +00:00
|
|
|
worker_queue_with_priority,
|
2012-12-06 14:41:24 +00:00
|
|
|
worker_queue_class,
|
|
|
|
abf_worker_args
|
|
|
|
)
|
2012-12-06 16:00:24 +00:00
|
|
|
if deleted == 1
|
2012-12-06 19:18:28 +00:00
|
|
|
build_canceled
|
2012-12-06 14:41:24 +00:00
|
|
|
else
|
|
|
|
send_stop_signal
|
|
|
|
end
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2012-12-28 14:00:37 +00:00
|
|
|
def worker_queue_with_priority(queue = nil)
|
|
|
|
queue ||= abf_worker_base_queue
|
|
|
|
queue << '_' << abf_worker_priority if abf_worker_priority.present?
|
|
|
|
queue
|
|
|
|
end
|
|
|
|
|
|
|
|
def worker_queue_class(queue_class = nil)
|
2012-12-28 19:11:58 +00:00
|
|
|
queue_class ||= "AbfWorker::#{abf_worker_base_queue.classify}"
|
2012-12-28 14:00:37 +00:00
|
|
|
queue_class << abf_worker_priority.capitalize
|
|
|
|
end
|
|
|
|
|
2012-12-06 14:41:24 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def send_stop_signal
|
|
|
|
Resque.redis.setex(
|
2012-12-28 14:00:37 +00:00
|
|
|
"#{service_queue}::live-inspector",
|
2012-12-07 11:22:41 +00:00
|
|
|
240, # Data will be removed from Redis after 240 sec.
|
2012-12-06 14:41:24 +00:00
|
|
|
'USR1' # Immediately kill child but don't exit
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2012-12-28 14:00:37 +00:00
|
|
|
def service_queue
|
|
|
|
"abfworker::#{abf_worker_base_queue.gsub(/\_/, '-')}-#{id}"
|
2012-12-06 14:41:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|