EnqueueSystemTask creates an on-demand task of the given type. The returned bool is true only when a new pending row was created; false means an active task of the same type already exists and was returned.
(taskType string, payload any)
| 199 | // bool is true only when a new pending row was created; false means an active |
| 200 | // task of the same type already exists and was returned. |
| 201 | func EnqueueSystemTask(taskType string, payload any) (*model.SystemTask, bool, error) { |
| 202 | activeTask, err := model.GetActiveSystemTask(taskType) |
| 203 | if err != nil { |
| 204 | return nil, false, err |
| 205 | } |
| 206 | if activeTask != nil { |
| 207 | return activeTask, false, nil |
| 208 | } |
| 209 | |
| 210 | task, err := model.CreateSystemTask(taskType, payload, nil) |
| 211 | if err != nil { |
| 212 | activeTask, activeErr := model.GetActiveSystemTask(taskType) |
| 213 | if activeErr == nil && activeTask != nil { |
| 214 | return activeTask, false, nil |
| 215 | } |
| 216 | return nil, false, err |
| 217 | } |
| 218 | notifySystemTaskRunner() |
| 219 | return task, true, nil |
| 220 | } |
| 221 | |
| 222 | // runSystemTaskClaimPass tries to claim one pending task per registered type |
| 223 | // and dispatches each claimed task in its own goroutine so a long-running |