fix(worker): lab5 enforce pipeline version check on claim
This commit is contained in:
@@ -42,19 +42,19 @@ func NewPipeline(
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Pipeline) Process(ctx context.Context, attachmentID string) error {
|
||||
log.Printf("worker: начало обработки %s", attachmentID)
|
||||
func (p *Pipeline) Process(ctx context.Context, attachmentID string, pipelineVersion int) error {
|
||||
log.Printf("worker: начало обработки %s (версия пайплайна %d)", attachmentID, pipelineVersion)
|
||||
|
||||
jobCtx, cancel := context.WithTimeout(ctx, 30*time.Second)
|
||||
defer cancel()
|
||||
|
||||
// 1. Забираем задачу (защита от дублей). Если уже взята или готова — nil.
|
||||
a, err := p.jobs.ClaimForProcessing(jobCtx, attachmentID, p.lease)
|
||||
// 1. Забираем задачу с проверкой версии
|
||||
a, err := p.jobs.ClaimForProcessing(jobCtx, attachmentID, pipelineVersion, p.lease)
|
||||
if err != nil {
|
||||
return fmt.Errorf("захват задачи: %w", err)
|
||||
}
|
||||
if a == nil {
|
||||
log.Printf("worker: задача %s уже взята или выполнена", attachmentID)
|
||||
log.Printf("worker: задача %s уже взята, выполнена или версия устарела", attachmentID)
|
||||
return nil // no-op
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user