gitlab-org--gitlab-foss/app/workers/propagate_service_template_worker.rb

22 lines
542 B
Ruby
Raw Normal View History

# Worker for updating any project specific caches.
2017-05-05 12:01:33 -04:00
class PropagateServiceTemplateWorker
include Sidekiq::Worker
include DedicatedSidekiqQueue
2017-05-04 06:21:35 -04:00
LEASE_TIMEOUT = 4.hours.to_i
def perform(template_id)
2017-05-04 06:13:33 -04:00
return unless try_obtain_lease_for(template_id)
2017-05-05 12:01:33 -04:00
Projects::PropagateServiceTemplate.propagate(Service.find_by(id: template_id))
end
private
def try_obtain_lease_for(template_id)
Gitlab::ExclusiveLease.
2017-05-05 12:01:33 -04:00
new("propagate_service_template_worker:#{template_id}", timeout: LEASE_TIMEOUT).
try_obtain
end
end