fix(tasks): 任务队列 - 限制缓存回源并修复并发租约与过期写入
This commit is contained in:
1 parent
1ff5e5cada
commit
bf0c4454fa
23 files changed
+1098
-59
No files matched your search
@@ -27,7 +27,7 @@ type taskTerminalCoordinator struct {
|
||||
|
||||
type taskTerminalRepository interface {
|
||||
Task(id string) (*model.Task, error)
|
||||
UpdateTaskTerminalState(id string, expected model.TaskStatus, status model.TaskStatus, stage string, errorText string, completedAt time.Time) (bool, error)
|
||||
UpdateTaskTerminalState(id string, owner string, expected model.TaskStatus, status model.TaskStatus, stage string, errorText string, completedAt time.Time) (bool, error)
|
||||
}
|
||||
|
||||
type taskBillingLifecycle interface {
|
||||
@@ -248,9 +248,13 @@ func (c *taskTerminalCoordinator) handleSuccess(task *model.Task) error {
|
||||
func (c *taskTerminalCoordinator) markTerminalState(task *model.Task) error {
|
||||
completedAt := time.Now()
|
||||
task.CompletedAt = &completedAt
|
||||
if _, err := c.repo.UpdateTaskTerminalState(task.ID, model.TaskStatusRunning, task.Status, task.Stage, task.Error, completedAt); err != nil {
|
||||
updated, err := c.repo.UpdateTaskTerminalState(task.ID, task.LeaseOwner, model.TaskStatusRunning, task.Status, task.Stage, task.Error, completedAt)
|
||||
if err != nil {
|
||||
return fmt.Errorf("写入任务终态失败:%w", err)
|
||||
}
|
||||
if !updated {
|
||||
return repository.ErrTaskStateConflict
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user