debian-mirror-gitlab/app/workers/projects/post_creation_worker.rb

39 lines
948 B
Ruby
Raw Normal View History

2021-04-29 21:17:54 +05:30
# frozen_string_literal: true
module Projects
class PostCreationWorker
include ApplicationWorker
2021-10-27 15:23:28 +05:30
data_consistency :always
2021-06-08 01:23:25 +05:30
sidekiq_options retry: 3
2021-04-29 21:17:54 +05:30
feature_category :source_code_management
idempotent!
def perform(project_id)
project = Project.find_by_id(project_id)
return unless project
2021-09-30 23:02:18 +05:30
create_prometheus_integration(project)
2021-04-29 21:17:54 +05:30
end
private
2021-09-30 23:02:18 +05:30
def create_prometheus_integration(project)
integration = project.find_or_initialize_integration(::Integrations::Prometheus.to_param)
2021-04-29 21:17:54 +05:30
# If the service has already been inserted in the database, that
# means it came from a template, and there's nothing more to do.
2021-09-30 23:02:18 +05:30
return if integration.persisted?
2021-04-29 21:17:54 +05:30
2021-09-30 23:02:18 +05:30
return unless integration.prometheus_available?
2021-04-29 21:17:54 +05:30
2021-09-30 23:02:18 +05:30
integration.save!
2021-04-29 21:17:54 +05:30
rescue ActiveRecord::RecordInvalid => e
Gitlab::ErrorTracking.track_exception(e, extra: { project_id: project.id })
end
end
end