Commit 30c4eea
feat: add generic ProgressType parameter to Job and Worker
The progress type was hardcoded to JobProgress
(string | boolean | number | object), so there was no way to get
type-safe progress when calling updateProgress() or when listening to
the progress event.
Add an optional ProgressType generic parameter, constrained to
JobProgress and defaulting to JobProgress, to MinimalJob, Job,
Processor, Worker and WorkerListener. Existing code that passes fewer
generics keeps compiling unchanged.
Because ProgressType is constrained to JobProgress, Job<..., P> stays
assignable to the internal MinimalJob helpers, which never read or
write progress, so the generic does not need to be threaded through
them. This also keeps the persistence contract intact, since progress
is ultimately serialized before being stored in the backend.
On Worker the parameter is added after the backend generic B so that
the existing public signature is not broken.
Sandboxed processors keep JobProgress by design, as progress crosses a
process boundary where the static type is lost. Queue side getters such
as getJob and Job.fromId also keep the default.
Closes #3721
Co-authored-by: claygeo <claygeo6@gmail.com>1 parent 94d3286 commit 30c4eea
6 files changed
Lines changed: 178 additions & 47 deletions
File tree
- docs/gitbook/guide/workers
- src
- classes
- interfaces
- types
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
136 | 163 | | |
137 | 164 | | |
138 | 165 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | | - | |
| 58 | + | |
| 59 | + | |
59 | 60 | | |
60 | 61 | | |
61 | 62 | | |
| |||
66 | 67 | | |
67 | 68 | | |
68 | 69 | | |
69 | | - | |
| 70 | + | |
70 | 71 | | |
71 | 72 | | |
72 | 73 | | |
| |||
539 | 540 | | |
540 | 541 | | |
541 | 542 | | |
542 | | - | |
| 543 | + | |
543 | 544 | | |
544 | 545 | | |
545 | 546 | | |
| |||
0 commit comments