Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build cancel check before adding stages #317

Merged
merged 2 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/travis/scheduler/jobs/limit/stages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def queueable?(job)
end

def queueable(job)
Travis::Stages.build(jobs(job.source_id)).startable
Travis::Stages.build(jobs(job.source_id), job.source_id).startable
end

def jobs(build_id)
Expand Down
8 changes: 7 additions & 1 deletion lib/travis/scheduler/model/stages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,19 @@

module Travis
module Stages
def self.build(jobs)
def self.build(jobs, build_id = nil)
return [] if build_id && build_canceled?(build_id)

jobs.each_with_object(Stage.new(nil, 0)) do |job, stage|
job = Job.new(*job.values_at(:id, :state, :stage))
stage << job unless job.finished?
end
end

def self.build_canceled?(id)
Build.find(id)&.canceled? || false
end

class Stage
attr_reader :parent, :num, :children

Expand Down
4 changes: 4 additions & 0 deletions lib/travis/scheduler/record/build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ class Build < ActiveRecord::Base
has_many :jobs, as: :source

serialize :config

def canceled?
state&.to_sym == :canceled
end
end
4 changes: 4 additions & 0 deletions lib/travis/scheduler/record/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ def finished?
FINISHED_STATES.include?(state.try(:to_sym))
end

def canceled?
state&.to_sym == :canceled
end

def queueable=(value)
if value
unless queueable
Expand Down