59 lines
1.4 KiB
Ruby
59 lines
1.4 KiB
Ruby
module AbfWorker
|
|
module ModelHelper
|
|
# In model which contains this helper should be:
|
|
# - #abf_worker_args
|
|
# - #build_canceled
|
|
|
|
def abf_worker_log
|
|
Resque.redis.get(service_queue) || I18n.t('layout.build_lists.log.not_available')
|
|
end
|
|
|
|
def add_job_to_abf_worker_queue
|
|
Resque.push(
|
|
worker_queue_with_priority,
|
|
'class' => worker_queue_class,
|
|
'args' => [abf_worker_args]
|
|
)
|
|
end
|
|
|
|
def cancel_job
|
|
deleted = Resque::Job.destroy(
|
|
worker_queue_with_priority,
|
|
worker_queue_class,
|
|
abf_worker_args
|
|
)
|
|
if deleted == 1
|
|
build_canceled
|
|
else
|
|
send_stop_signal
|
|
end
|
|
true
|
|
end
|
|
|
|
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)
|
|
queue_class ||= "AbfWorker::#{abf_worker_base_queue.classify}"
|
|
queue_class << abf_worker_priority.capitalize
|
|
end
|
|
|
|
private
|
|
|
|
def send_stop_signal
|
|
Resque.redis.setex(
|
|
"#{service_queue}::live-inspector",
|
|
240, # Data will be removed from Redis after 240 sec.
|
|
'USR1' # Immediately kill child but don't exit
|
|
)
|
|
end
|
|
|
|
def service_queue
|
|
"abfworker::#{abf_worker_base_queue.gsub(/\_/, '-')}-#{id}"
|
|
end
|
|
|
|
end
|
|
end |