debian-mirror-gitlab/app/workers/pipeline_metrics_worker.rb

38 lines
1.2 KiB
Ruby
Raw Normal View History

2018-11-08 19:23:39 +05:30
# frozen_string_literal: true
2016-11-03 12:29:30 +05:30
class PipelineMetricsWorker
2018-03-17 18:26:18 +05:30
include ApplicationWorker
2016-11-03 12:29:30 +05:30
include PipelineQueue
2019-12-26 22:10:19 +05:30
latency_sensitive_worker!
2018-12-05 23:21:45 +05:30
# rubocop: disable CodeReuse/ActiveRecord
2016-11-03 12:29:30 +05:30
def perform(pipeline_id)
Ci::Pipeline.find_by(id: pipeline_id).try do |pipeline|
update_metrics_for_active_pipeline(pipeline) if pipeline.active?
update_metrics_for_succeeded_pipeline(pipeline) if pipeline.success?
end
end
2018-12-05 23:21:45 +05:30
# rubocop: enable CodeReuse/ActiveRecord
2016-11-03 12:29:30 +05:30
private
def update_metrics_for_active_pipeline(pipeline)
2017-08-17 22:00:37 +05:30
metrics(pipeline).update_all(latest_build_started_at: pipeline.started_at, latest_build_finished_at: nil, pipeline_id: pipeline.id)
2016-11-03 12:29:30 +05:30
end
def update_metrics_for_succeeded_pipeline(pipeline)
2017-08-17 22:00:37 +05:30
metrics(pipeline).update_all(latest_build_started_at: pipeline.started_at, latest_build_finished_at: pipeline.finished_at, pipeline_id: pipeline.id)
2016-11-03 12:29:30 +05:30
end
2018-12-05 23:21:45 +05:30
# rubocop: disable CodeReuse/ActiveRecord
2016-11-03 12:29:30 +05:30
def metrics(pipeline)
MergeRequest::Metrics.where(merge_request_id: merge_requests(pipeline))
end
2018-12-05 23:21:45 +05:30
# rubocop: enable CodeReuse/ActiveRecord
2016-11-03 12:29:30 +05:30
def merge_requests(pipeline)
2019-07-07 11:18:12 +05:30
pipeline.merge_requests_as_head_pipeline.map(&:id)
2016-11-03 12:29:30 +05:30
end
end