2018-06-27 03:23:28 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-07 18:35:56 -04:00
|
|
|
class PipelineScheduleWorker
|
2017-11-28 11:08:30 -05:00
|
|
|
include ApplicationWorker
|
2017-05-07 18:35:56 -04:00
|
|
|
include CronjobQueue
|
|
|
|
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2017-05-07 18:35:56 -04:00
|
|
|
def perform
|
2017-05-10 04:04:25 -04:00
|
|
|
Ci::PipelineSchedule.active.where("next_run_at < ?", Time.now)
|
|
|
|
.preload(:owner, :project).find_each do |schedule|
|
2017-05-07 18:35:56 -04:00
|
|
|
begin
|
2018-11-30 02:32:30 -05:00
|
|
|
Ci::CreatePipelineService.new(schedule.project,
|
|
|
|
schedule.owner,
|
|
|
|
ref: schedule.ref)
|
|
|
|
.execute!(:schedule, ignore_skip_ci: true, save_on_errors: true, schedule: schedule)
|
2017-05-07 18:35:56 -04:00
|
|
|
rescue => e
|
2018-11-30 02:32:30 -05:00
|
|
|
error(schedule, e)
|
2017-05-07 18:35:56 -04:00
|
|
|
ensure
|
|
|
|
schedule.schedule_next_run!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2018-11-30 02:32:30 -05:00
|
|
|
|
|
|
|
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-05-07 18:35:56 -04:00
|
|
|
end
|