Commit 66df34c
authored
Add GenericEnqueuer for consistent job priorities (#4237)
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) |1 parent 2b6b992 commit 66df34c
File tree
30 files changed
+305
-65
lines changed- app
- actions
- mixins
- routing
- services
- locks
- v2/services
- v3
- jobs
- runtime
- v2/services
- lib/services/service_brokers/v2
- spec/unit
- actions
- jobs
- lib/services/service_brokers/v2
30 files changed
+305
-65
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
100 | | - | |
| 100 | + | |
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
| 63 | + | |
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
22 | | - | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
1 | 3 | | |
2 | 4 | | |
3 | 5 | | |
| |||
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
13 | | - | |
| 15 | + | |
14 | 16 | | |
15 | 17 | | |
16 | 18 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
| 34 | + | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| |||
0 commit comments