BigW Consortium Gitlab

pipeline_schedule_worker.rb 773 Bytes
Newer Older
1 2 3 4 5
class PipelineScheduleWorker
  include Sidekiq::Worker
  include CronjobQueue

  def perform
6 7
    Ci::PipelineSchedule.active.where("next_run_at < ?", Time.now)
      .preload(:owner, :project).find_each do |schedule|
8
      begin
9 10 11
        pipeline = Ci::CreatePipelineService.new(schedule.project,
                                                 schedule.owner,
                                                 ref: schedule.ref)
12
          .execute(:schedule, ignore_skip_ci: true, save_on_errors: false, schedule: schedule)
13 14

        schedule.deactivate! unless pipeline.persisted?
15 16 17 18 19 20 21 22
      rescue => e
        Rails.logger.error "#{schedule.id}: Failed to create a scheduled pipeline: #{e.message}"
      ensure
        schedule.schedule_next_run!
      end
    end
  end
end