-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement separate long build queues
This implements a separate queue for long-running builds that are identified by a tag `-long` in the runner name.
- Loading branch information
Showing
3 changed files
with
42 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "shared_state" | ||
|
||
class JobQueue | ||
def initialize | ||
@mutex = Mutex.new | ||
@queue = Hash.new { |h,k| h[k] = Queue.new } | ||
@state = SharedState.instance | ||
end | ||
|
||
def <<(job) | ||
@mutex.synchronize do | ||
@queue[job.type] << job | ||
end | ||
end | ||
|
||
def pop | ||
@mutex.synchronize do | ||
running_long_build_count = @state.running_jobs | ||
.count { |job| job.type == :long } | ||
if running_long_build_count < 2 | ||
@queue[:long].pop | ||
else | ||
@queue[:standard].pop | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters