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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

54 lines
1.6 KiB
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)
2023-01-13 00:05:48 +05:30
create_incident_management_timeline_event_tags(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
2023-01-13 00:05:48 +05:30
def create_incident_management_timeline_event_tags(project)
tags = project.incident_management_timeline_event_tags.pluck_names
start_time_name = ::IncidentManagement::TimelineEventTag::START_TIME_TAG_NAME
end_time_name = ::IncidentManagement::TimelineEventTag::END_TIME_TAG_NAME
project.incident_management_timeline_event_tags.new(name: start_time_name) unless tags.include?(start_time_name)
project.incident_management_timeline_event_tags.new(name: end_time_name) unless tags.include?(end_time_name)
project.save!
rescue StandardError => e
Gitlab::ErrorTracking.track_exception(e, extra: { project_id: project.id })
end
2021-04-29 21:17:54 +05:30
end
end