-
Notifications
You must be signed in to change notification settings - Fork 362
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GenericEnqueuer for consistent job priorities
Some delayed jobs enqueue other delayed jobs. For example, an app delete job may enqueue secondary jobs like blobstore deletion and buildpack cache cleanup. If CAPI is configured with dedicated job priorities or dynamic job priorities is enabled, these secondary jobs might unintentionally receive a higher priority than their primary job. This could lead to less critical jobs, like blobstore deletion, being processed before more critical ones, such as service instance creation. This change introduces `GenericEnqueuer`, a singleton enqueuer ensuring that all jobs enqueued within the same job execution context inherit the same priority. It is automatically initialized and destroyed within the CCJob wrapper, ensuring consistent priority propagation. Jobs can now be enqueued using: `GenericEnqueuer.shared.enqueue(job)` - **Priority Incrementation:** - `enqueue` and `enqueue_pollable` now support an optional `priority_increment` parameter. - This increases the priority value (making the job less important), allowing secondary jobs (e.g., blobstore deletion) to have a lower priority than their parent job. - **Preserving Priority for Re-enqueued Jobs:** - The `preserve_priority` flag ensures that re-enqueued jobs retain their previous priority. - Prevents unnecessary priority increases on repeated executions. - **Config Priority Handling:** - If a job has a dedicated priority configured, it is added to the current priority and `priority_increment`, ensuring correct propagation. | Job Type | Preserve Priority | Config Priority | Increment | Final Priority | |------------------------|-------------------|-----------------|-----------|--------------------------------------| | **Parent Job** | ❌ No | `100` | `nil` | **100** | | **Sub-Job A** | ❌ No | `200` | `50` | **350** (100+200+50) | | **Sub-Job B** | ❌ No | `nil` | `50` | **150** (100+50) | | **Sub-Job C** | ❌ No | `nil` | `nil` | **100** (inherits parent) | | **Tertiary Job A1** | ❌ No | `50` | `20` | **420** (350+50+20) | | **Tertiary Job B1** | ✅ Yes | `10` (ignored) | `30` | **150** (preserved from Sub-Job B) | | **Tertiary Job C1** | ❌ No | `nil` | `50` | **150** (100+50) | | **Re-enqueued Job** | ✅ Yes | `20` (ignored) | `100` | **42** (original preserved priority) | Co-authored-by: Johannes Haass <[email protected]>
- Loading branch information
Showing
31 changed files
with
308 additions
and
65 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
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
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
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
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
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
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
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
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
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
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,20 @@ | ||
module VCAP::CloudController | ||
module Jobs | ||
REDUCED_PRIORITY = 50 | ||
|
||
class GenericEnqueuer < Enqueuer | ||
def self.shared(priority: nil) | ||
stored_instance = Thread.current[:generic_enqueuer] | ||
return stored_instance if stored_instance && priority.nil? | ||
|
||
new_instance = new(queue: Jobs::Queues.generic, priority: priority) | ||
Thread.current[:generic_enqueuer] ||= new_instance | ||
new_instance | ||
end | ||
|
||
def self.reset! | ||
Thread.current[:generic_enqueuer] = nil | ||
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
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
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
Oops, something went wrong.