2020-03-24 05:09:25 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2021-04-21 20:10:01 -04:00
|
|
|
# Deprecated, to be removed in %14.0 as part of https://gitlab.com/groups/gitlab-org/-/epics/4280
|
2020-03-24 05:09:25 -04:00
|
|
|
class ClusterUpdateAppWorker # rubocop:disable Scalability/IdempotentWorker
|
|
|
|
UpdateAlreadyInProgressError = Class.new(StandardError)
|
|
|
|
|
|
|
|
include ApplicationWorker
|
2021-07-21 08:09:35 -04:00
|
|
|
|
|
|
|
data_consistency :always
|
2020-03-24 05:09:25 -04:00
|
|
|
include ClusterQueue
|
|
|
|
include ClusterApplications
|
|
|
|
include ExclusiveLeaseGuard
|
|
|
|
|
|
|
|
sidekiq_options retry: 3, dead: false
|
2020-06-12 08:08:56 -04:00
|
|
|
loggable_arguments 0, 3
|
2020-03-24 05:09:25 -04:00
|
|
|
|
|
|
|
LEASE_TIMEOUT = 10.minutes.to_i
|
|
|
|
|
|
|
|
def perform(app_name, app_id, project_id, scheduled_time)
|
|
|
|
@app_id = app_id
|
|
|
|
|
|
|
|
try_obtain_lease do
|
|
|
|
execute(app_name, app_id, project_id, scheduled_time)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def execute(app_name, app_id, project_id, scheduled_time)
|
2021-11-10 10:13:21 -05:00
|
|
|
project = Project.find_by_id(project_id)
|
2020-03-24 05:09:25 -04:00
|
|
|
return unless project
|
|
|
|
|
|
|
|
find_application(app_name, app_id) do |app|
|
|
|
|
update_prometheus(app, scheduled_time, project)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_prometheus(app, scheduled_time, project)
|
2021-04-21 20:10:01 -04:00
|
|
|
return unless app.managed_prometheus?
|
2020-03-24 05:09:25 -04:00
|
|
|
return if app.updated_since?(scheduled_time)
|
|
|
|
return if app.update_in_progress?
|
|
|
|
|
|
|
|
Clusters::Applications::PrometheusUpdateService.new(app, project).execute
|
|
|
|
end
|
|
|
|
|
|
|
|
def lease_key
|
|
|
|
@lease_key ||= "#{self.class.name.underscore}-#{@app_id}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def lease_timeout
|
|
|
|
LEASE_TIMEOUT
|
|
|
|
end
|
|
|
|
end
|