Commit 6749230
committed
Add GenericEnqueuer for consistent job priorities
Some of the delayed jobs enqueue other delayed jobs. An example for this is an app delete job which enqueues other jobs like blobstore delete and buildpack cache cleanup.
If CAPI is configured with dedicated job priorities or when dynamic job priorities is enabled, those secondary jobs might end up with a higher priority then the primary job.
This might result in less important jobs like blobstore delete to have a higher priority than more important ones like service instance create.
This change introduces a `GenericEnqueuer` which follows the singleton pattern to ensure that always the same enqueuer instance is used in context of the current thread.
`GenericEnqueuer` will be initialized and destroyed in the CCJob wrapper and therefore every job which gets enqueued by `GenericEnqueuer.shared.enqueue(job)` will have the same priority.
Additionally the `enqueue` and `enqueue_pollable` methods allow an optional `priority_increment` which increases the priority value and thus makes the job less important.
With this we can give secondary jobs a lower priority then their parent useful for e.g. blobstore delete jobs.
If a job has a dedicated priority configured this priority will be added to the current priority and `priority_increment`, ensuring that the priorities of the primary job are correctly applied.
For reoccurring jobs the priority can be locked with the `preserve_priority` parameter which will ensure the current/previous priority is used again.
| 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 fad2da1 commit 6749230
File tree
32 files changed
+310
-66
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
32 files changed
+310
-66
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