GetLatestSystemTask returns the most recent task row of the given type (any status) so the scheduler can decide whether enough time has elapsed since the last run. Returns (nil, nil) when no row exists.
(taskType string)
| 191 | // (any status) so the scheduler can decide whether enough time has elapsed |
| 192 | // since the last run. Returns (nil, nil) when no row exists. |
| 193 | func GetLatestSystemTask(taskType string) (*SystemTask, error) { |
| 194 | var task SystemTask |
| 195 | err := DB.Where("type = ?", taskType).Order("id desc").First(&task).Error |
| 196 | if err != nil { |
| 197 | if errors.Is(err, gorm.ErrRecordNotFound) { |
| 198 | return nil, nil |
| 199 | } |
| 200 | return nil, err |
| 201 | } |
| 202 | return &task, nil |
| 203 | } |
| 204 | |
| 205 | func GetLatestSystemTasks(taskTypes []string) (map[string]*SystemTask, error) { |
| 206 | tasksByType := map[string]*SystemTask{} |
no outgoing calls