2018-06-27 07:23:28 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-02-19 18:09:10 +00:00
|
|
|
class RunPipelineScheduleWorker # rubocop:disable Scalability/IdempotentWorker
|
2017-12-08 07:58:05 +00:00
|
|
|
include ApplicationWorker
|
2017-12-03 06:55:49 +00:00
|
|
|
include PipelineQueue
|
|
|
|
|
2017-12-18 15:42:31 +00:00
|
|
|
queue_namespace :pipeline_creation
|
2019-10-18 11:11:44 +00:00
|
|
|
feature_category :continuous_integration
|
2017-12-03 06:55:49 +00:00
|
|
|
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2017-12-03 06:55:49 +00:00
|
|
|
def perform(schedule_id, user_id)
|
2017-12-06 06:24:20 +00:00
|
|
|
schedule = Ci::PipelineSchedule.find_by(id: schedule_id)
|
|
|
|
user = User.find_by(id: user_id)
|
|
|
|
|
|
|
|
return unless schedule && user
|
2017-12-03 06:55:49 +00:00
|
|
|
|
|
|
|
run_pipeline_schedule(schedule, user)
|
|
|
|
end
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2017-12-03 06:55:49 +00:00
|
|
|
|
|
|
|
def run_pipeline_schedule(schedule, user)
|
|
|
|
Ci::CreatePipelineService.new(schedule.project,
|
|
|
|
user,
|
|
|
|
ref: schedule.ref)
|
2019-05-17 12:10:44 +00:00
|
|
|
.execute!(:schedule, ignore_skip_ci: true, save_on_errors: false, schedule: schedule)
|
|
|
|
rescue Ci::CreatePipelineService::CreateError
|
|
|
|
# no-op. This is a user operation error such as corrupted .gitlab-ci.yml.
|
|
|
|
rescue => e
|
|
|
|
error(schedule, e)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def error(schedule, error)
|
|
|
|
failed_creation_counter.increment
|
|
|
|
|
2020-09-08 09:08:31 +00:00
|
|
|
Gitlab::AppLogger.error "Failed to create a scheduled pipeline. " \
|
2019-05-17 12:10:44 +00:00
|
|
|
"schedule_id: #{schedule.id} message: #{error.message}"
|
|
|
|
|
2019-12-16 12:07:43 +00:00
|
|
|
Gitlab::ErrorTracking
|
2019-12-13 12:07:41 +00:00
|
|
|
.track_and_raise_for_dev_exception(error,
|
2019-09-18 14:02:45 +00:00
|
|
|
issue_url: 'https://gitlab.com/gitlab-org/gitlab-foss/issues/41231',
|
2019-12-13 12:07:41 +00:00
|
|
|
schedule_id: schedule.id)
|
2019-05-17 12:10:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def failed_creation_counter
|
|
|
|
@failed_creation_counter ||=
|
|
|
|
Gitlab::Metrics.counter(:pipeline_schedule_creation_failed_total,
|
|
|
|
"Counter of failed attempts of pipeline schedule creation")
|
2017-12-03 06:55:49 +00:00
|
|
|
end
|
|
|
|
end
|