2018-11-08 19:23:39 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
class PipelineScheduleWorker
|
2018-03-17 18:26:18 +05:30
|
|
|
include ApplicationWorker
|
2017-08-17 22:00:37 +05:30
|
|
|
include CronjobQueue
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2017-08-17 22:00:37 +05:30
|
|
|
def perform
|
2017-09-10 17:25:29 +05:30
|
|
|
Ci::PipelineSchedule.active.where("next_run_at < ?", Time.now)
|
|
|
|
.preload(:owner, :project).find_each do |schedule|
|
2017-08-17 22:00:37 +05:30
|
|
|
begin
|
2018-12-23 12:14:25 +05:30
|
|
|
Ci::CreatePipelineService.new(schedule.project,
|
|
|
|
schedule.owner,
|
|
|
|
ref: schedule.ref)
|
|
|
|
.execute!(:schedule, ignore_skip_ci: true, save_on_errors: true, schedule: schedule)
|
2017-08-17 22:00:37 +05:30
|
|
|
rescue => e
|
2018-12-23 12:14:25 +05:30
|
|
|
error(schedule, e)
|
2017-08-17 22:00:37 +05:30
|
|
|
ensure
|
|
|
|
schedule.schedule_next_run!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2018-12-23 12:14:25 +05:30
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def error(schedule, error)
|
|
|
|
failed_creation_counter.increment
|
|
|
|
|
|
|
|
Rails.logger.error "Failed to create a scheduled pipeline. " \
|
|
|
|
"schedule_id: #{schedule.id} message: #{error.message}"
|
|
|
|
|
|
|
|
Gitlab::Sentry
|
|
|
|
.track_exception(error,
|
|
|
|
issue_url: 'https://gitlab.com/gitlab-org/gitlab-ce/issues/41231',
|
|
|
|
extra: { schedule_id: schedule.id })
|
|
|
|
end
|
|
|
|
|
|
|
|
def failed_creation_counter
|
|
|
|
@failed_creation_counter ||=
|
|
|
|
Gitlab::Metrics.counter(:pipeline_schedule_creation_failed_total,
|
|
|
|
"Counter of failed attempts of pipeline schedule creation")
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|