2020-02-11 13:08:58 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Worker for updating any project specific caches.
|
2020-02-19 13:09:10 -05:00
|
|
|
class PropagateServiceTemplateWorker # rubocop:disable Scalability/IdempotentWorker
|
2020-02-11 13:08:58 -05:00
|
|
|
include ApplicationWorker
|
|
|
|
|
2020-07-31 08:10:02 -04:00
|
|
|
feature_category :integrations
|
2020-02-11 13:08:58 -05:00
|
|
|
|
|
|
|
LEASE_TIMEOUT = 4.hours.to_i
|
|
|
|
|
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
|
|
|
def perform(template_id)
|
|
|
|
return unless try_obtain_lease_for(template_id)
|
|
|
|
|
|
|
|
Projects::PropagateServiceTemplate.propagate(Service.find_by(id: template_id))
|
|
|
|
end
|
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def try_obtain_lease_for(template_id)
|
|
|
|
Gitlab::ExclusiveLease
|
|
|
|
.new("propagate_service_template_worker:#{template_id}", timeout: LEASE_TIMEOUT)
|
|
|
|
.try_obtain
|
|
|
|
end
|
|
|
|
end
|