2018-06-27 03:23:28 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-03 11:20:12 -04:00
|
|
|
# Worker for updating any project specific caches.
|
2017-05-05 12:01:33 -04:00
|
|
|
class PropagateServiceTemplateWorker
|
2017-11-28 11:08:30 -05:00
|
|
|
include ApplicationWorker
|
2017-05-03 11:20:12 -04:00
|
|
|
|
2019-10-18 07:11:44 -04:00
|
|
|
feature_category :source_code_management
|
|
|
|
|
2017-05-04 06:21:35 -04:00
|
|
|
LEASE_TIMEOUT = 4.hours.to_i
|
2017-05-03 11:20:12 -04:00
|
|
|
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2017-05-03 11:20:12 -04:00
|
|
|
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-05 12:01:33 -04:00
|
|
|
Projects::PropagateServiceTemplate.propagate(Service.find_by(id: template_id))
|
2017-05-03 11:20:12 -04:00
|
|
|
end
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2017-05-03 11:20:12 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def try_obtain_lease_for(template_id)
|
2017-06-21 09:48:12 -04:00
|
|
|
Gitlab::ExclusiveLease
|
|
|
|
.new("propagate_service_template_worker:#{template_id}", timeout: LEASE_TIMEOUT)
|
|
|
|
.try_obtain
|
2017-05-03 11:20:12 -04:00
|
|
|
end
|
|
|
|
end
|