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

38 lines
917 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-06-08 01:23:25 +05:30
sidekiq_options retry: 3
2021-04-29 21:17:54 +05:30
feature_category :source_code_management
2021-06-08 01:23:25 +05:30
tags :exclude_from_kubernetes
2021-04-29 21:17:54 +05:30
idempotent!
def perform(project_id)
project = Project.find_by_id(project_id)
return unless project
create_prometheus_service(project)
end
private
def create_prometheus_service(project)
service = project.find_or_initialize_service(::PrometheusService.to_param)
# If the service has already been inserted in the database, that
# means it came from a template, and there's nothing more to do.
return if service.persisted?
return unless service.prometheus_available?
service.save!
rescue ActiveRecord::RecordInvalid => e
Gitlab::ErrorTracking.track_exception(e, extra: { project_id: project.id })
end
end
end