@@ -268,6 +268,7 @@ FROM electronic_signatures
|
||||
WHERE status = 'COMPLETED'
|
||||
AND certificate_file_id IS NULL
|
||||
AND certificate_processing_started_at IS NULL
|
||||
AND attempt_count < max_attempts
|
||||
ORDER BY signed_at ASC
|
||||
LIMIT 1
|
||||
FOR UPDATE SKIP LOCKED
|
||||
@@ -362,6 +363,7 @@ WHERE status = 'COMPLETED'
|
||||
AND certificate_file_id IS NULL
|
||||
AND certificate_processing_started_at IS NOT NULL
|
||||
AND certificate_processing_started_at < NOW() - $1::interval
|
||||
AND attempt_count < max_attempts
|
||||
`
|
||||
_, err := conn.Exec(ctx, q, staleAfter)
|
||||
if err != nil {
|
||||
|
||||
@@ -151,6 +151,8 @@ func (w *CompletionCertificateWorker) processNext(ctx context.Context, sem chan
|
||||
}
|
||||
scope := coredata.NewScopeFromObjectID(signature.ID)
|
||||
signature.CertificateProcessingStartedAt = &now
|
||||
signature.AttemptCount++
|
||||
signature.LastAttemptedAt = &now
|
||||
signature.UpdatedAt = now
|
||||
|
||||
if err := signature.Update(nonCancelableCtx, tx, scope); err != nil {
|
||||
@@ -353,9 +355,15 @@ func (w *CompletionCertificateWorker) handleCertFailure(
|
||||
return w.pg.WithTx(
|
||||
ctx,
|
||||
func(tx pg.Conn) error {
|
||||
errStr := processingError.Error()
|
||||
signature.LastError = &errStr
|
||||
signature.CertificateProcessingStartedAt = nil
|
||||
signature.UpdatedAt = time.Now()
|
||||
|
||||
if signature.AttemptCount >= signature.MaxAttempts {
|
||||
signature.Status = coredata.ElectronicSignatureStatusFailed
|
||||
}
|
||||
|
||||
if err := signature.Update(ctx, tx, scope); err != nil {
|
||||
return fmt.Errorf("cannot update signature: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user