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

23 lines
751 B
Ruby
Raw Normal View History

2017-08-17 22:00:37 +05:30
class PipelineScheduleWorker
include Sidekiq::Worker
include CronjobQueue
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
2017-09-10 17:25:29 +05:30
pipeline = Ci::CreatePipelineService.new(schedule.project,
schedule.owner,
ref: schedule.ref)
.execute(:schedule, save_on_errors: false, schedule: schedule)
schedule.deactivate! unless pipeline.persisted?
2017-08-17 22:00:37 +05:30
rescue => e
Rails.logger.error "#{schedule.id}: Failed to create a scheduled pipeline: #{e.message}"
ensure
schedule.schedule_next_run!
end
end
end
end