debian-mirror-gitlab/app/services/clusters/applications/schedule_update_service.rb

41 lines
1.1 KiB
Ruby
Raw Normal View History

2020-04-22 19:07:51 +05:30
# frozen_string_literal: true
2021-09-04 01:27:46 +05:30
# DEPRECATED: To be removed as part of https://gitlab.com/groups/gitlab-org/-/epics/5877
2020-04-22 19:07:51 +05:30
module Clusters
module Applications
class ScheduleUpdateService
BACKOFF_DELAY = 2.minutes
attr_accessor :application, :project
2021-09-04 01:27:46 +05:30
def initialize(cluster_prometheus_adapter, project)
@application = cluster_prometheus_adapter&.cluster&.application_prometheus
2020-04-22 19:07:51 +05:30
@project = project
end
def execute
return unless application
2021-09-04 01:27:46 +05:30
return if application.externally_installed?
2020-04-22 19:07:51 +05:30
if recently_scheduled?
2020-05-24 23:13:21 +05:30
worker_class.perform_in(BACKOFF_DELAY, application.name, application.id, project.id, Time.current)
2020-04-22 19:07:51 +05:30
else
2020-05-24 23:13:21 +05:30
worker_class.perform_async(application.name, application.id, project.id, Time.current)
2020-04-22 19:07:51 +05:30
end
end
private
def worker_class
::ClusterUpdateAppWorker
end
def recently_scheduled?
return false unless application.last_update_started_at
2020-05-24 23:13:21 +05:30
application.last_update_started_at.utc >= Time.current.utc - BACKOFF_DELAY
2020-04-22 19:07:51 +05:30
end
end
end
end