2017-05-07 22:35:56 +00:00
|
|
|
class PipelineScheduleWorker
|
|
|
|
include Sidekiq::Worker
|
|
|
|
include CronjobQueue
|
|
|
|
|
|
|
|
def perform
|
2017-05-10 08:04:25 +00:00
|
|
|
Ci::PipelineSchedule.active.where("next_run_at < ?", Time.now)
|
|
|
|
.preload(:owner, :project).find_each do |schedule|
|
2017-05-07 22:35:56 +00:00
|
|
|
begin
|
2017-05-10 08:04:25 +00:00
|
|
|
unless schedule.runnable_by_owner?
|
|
|
|
schedule.deactivate!
|
|
|
|
next
|
|
|
|
end
|
|
|
|
|
2017-05-07 22:35:56 +00:00
|
|
|
Ci::CreatePipelineService.new(schedule.project,
|
|
|
|
schedule.owner,
|
|
|
|
ref: schedule.ref)
|
|
|
|
.execute(save_on_errors: false, schedule: schedule)
|
|
|
|
rescue => e
|
|
|
|
Rails.logger.error "#{schedule.id}: Failed to create a scheduled pipeline: #{e.message}"
|
|
|
|
ensure
|
|
|
|
schedule.schedule_next_run!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|