gitlab-org--gitlab-foss/app/workers/propagate_service_template_...

27 lines
674 B
Ruby
Raw Normal View History

# frozen_string_literal: true
# Worker for updating any project specific caches.
2017-05-05 16:01:33 +00:00
class PropagateServiceTemplateWorker
include ApplicationWorker
feature_category :source_code_management
2017-05-04 10:21:35 +00:00
LEASE_TIMEOUT = 4.hours.to_i
# rubocop: disable CodeReuse/ActiveRecord
def perform(template_id)
2017-05-04 10:13:33 +00:00
return unless try_obtain_lease_for(template_id)
2017-05-05 16:01:33 +00:00
Projects::PropagateServiceTemplate.propagate(Service.find_by(id: template_id))
end
# rubocop: enable CodeReuse/ActiveRecord
private
def try_obtain_lease_for(template_id)
2017-06-21 13:48:12 +00:00
Gitlab::ExclusiveLease
.new("propagate_service_template_worker:#{template_id}", timeout: LEASE_TIMEOUT)
.try_obtain
end
end