2017-05-03 11:20:12 -04:00
|
|
|
# Worker for updating any project specific caches.
|
|
|
|
class PropagateProjectServiceWorker
|
|
|
|
include Sidekiq::Worker
|
|
|
|
include DedicatedSidekiqQueue
|
|
|
|
|
2017-05-04 06:13:33 -04:00
|
|
|
sidekiq_options retry: 3
|
|
|
|
|
2017-05-03 11:20:12 -04:00
|
|
|
LEASE_TIMEOUT = 30.minutes.to_i
|
|
|
|
|
|
|
|
def perform(template_id)
|
2017-05-04 06:13:33 -04:00
|
|
|
return unless try_obtain_lease_for(template_id)
|
2017-05-03 11:20:12 -04:00
|
|
|
|
2017-05-04 06:13:33 -04:00
|
|
|
Projects::PropagateService.propagate!(Service.find_by(id: template_id))
|
2017-05-03 11:20:12 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def try_obtain_lease_for(template_id)
|
|
|
|
Gitlab::ExclusiveLease.
|
|
|
|
new("propagate_project_service_worker:#{template_id}", timeout: LEASE_TIMEOUT).
|
|
|
|
try_obtain
|
|
|
|
end
|
|
|
|
end
|