chore: commit workspace updates
This commit is contained in:
1 parent
01a2d171f5
commit
9727656b2b
491 files changed
+12826
-72249
No files matched your search
@@ -0,0 +1,39 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"infinite-canvas/backend/internal/model"
|
||||
)
|
||||
|
||||
type providerSubmissionKeyContext struct{}
|
||||
|
||||
func withProviderSubmissionKey(ctx context.Context, attempt *model.RouteAttempt) context.Context {
|
||||
if attempt == nil {
|
||||
return ctx
|
||||
}
|
||||
// Stable for this persisted attempt across worker/process recovery; an
|
||||
// explicitly new user retry or a safely rejected route gets a new attempt.
|
||||
key := uuid.NewSHA1(uuid.NameSpaceOID, []byte(attempt.TaskID+":"+attempt.ID)).String()
|
||||
return context.WithValue(ctx, providerSubmissionKeyContext{}, key)
|
||||
}
|
||||
|
||||
func (s *Service) createDirectTaskAttempt(task *model.Task) (*model.RouteAttempt, error) {
|
||||
if task.Attempts > 1 && task.ProviderRequestID == "" {
|
||||
return nil, routeDispatchUncertainError{"旧任务已尝试执行但缺少提交记录,为避免重复扣费已停止自动重发"}
|
||||
}
|
||||
id, err := s.repo.NextPrefixedID("ATTEMPT")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
attempt := &model.RouteAttempt{ID: id, TaskID: task.ID, RouteRun: task.RouteRun, AttemptNumber: 1, ChannelModelID: task.ChannelModelID, Status: "selected", DispatchState: "not_sent", StartedAt: time.Now()}
|
||||
if task.ProviderRequestID != "" {
|
||||
attempt.ProviderRequestID, attempt.DispatchState = task.ProviderRequestID, "accepted"
|
||||
}
|
||||
if err := s.repo.CreateRouteAttempt(attempt); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return attempt, nil
|
||||
}
|
||||
Reference in new issue
Block a user