2018-11-08 19:23:39 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
# Worker for updating any project specific caches.
|
2020-04-08 14:13:33 +05:30
|
|
|
class PropagateServiceTemplateWorker # rubocop:disable Scalability/IdempotentWorker
|
2018-03-17 18:26:18 +05:30
|
|
|
include ApplicationWorker
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
feature_category :source_code_management
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
LEASE_TIMEOUT = 4.hours.to_i
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2017-08-17 22:00:37 +05:30
|
|
|
def perform(template_id)
|
|
|
|
return unless try_obtain_lease_for(template_id)
|
|
|
|
|
|
|
|
Projects::PropagateServiceTemplate.propagate(Service.find_by(id: template_id))
|
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def try_obtain_lease_for(template_id)
|
2017-09-10 17:25:29 +05:30
|
|
|
Gitlab::ExclusiveLease
|
|
|
|
.new("propagate_service_template_worker:#{template_id}", timeout: LEASE_TIMEOUT)
|
|
|
|
.try_obtain
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|