lab5 done
This commit is contained in:
@@ -139,7 +139,7 @@ func (s *Service) reconcileObject(ctx context.Context, key string, cutoff time.T
|
||||
defer tx.Rollback(context.Background())
|
||||
var exists bool
|
||||
r.DBQueries++
|
||||
if err = tx.QueryRow(ctx, `SELECT EXISTS(SELECT 1 FROM attachments WHERE object_key=$1)`, key).Scan(&exists); err != nil {
|
||||
if err = tx.QueryRow(ctx, `SELECT EXISTS(SELECT 1 FROM attachments WHERE object_key=$1 OR staging_key=$1 OR $1 LIKE 'original/'||id::text||'/v'||pipeline_version::text||'/%')`, key).Scan(&exists); err != nil {
|
||||
return fmt.Errorf("metadata recheck failed")
|
||||
}
|
||||
if exists {
|
||||
@@ -207,9 +207,12 @@ func (s *Service) reconcileMetadata(ctx context.Context, id, key string, cutoff
|
||||
}
|
||||
if apply {
|
||||
r.DBQueries++
|
||||
if _, err = tx.Exec(ctx, `UPDATE attachments SET status='failed',error_code='original_missing' WHERE id=$1 AND status='ready'`, id); err != nil {
|
||||
if _, err = tx.Exec(ctx, `UPDATE attachments SET status='failed',error_code='original_missing',updated_at=clock_timestamp() WHERE id=$1 AND status='ready'`, id); err != nil {
|
||||
return fmt.Errorf("mark missing failed")
|
||||
}
|
||||
if _, err = tx.Exec(ctx, `UPDATE attachment_jobs SET state='failed',last_error='original_missing',fence=fence+1,updated_at=clock_timestamp() WHERE attachment_id=$1 AND state='ready'`, id); err != nil {
|
||||
return fmt.Errorf("mark job missing failed")
|
||||
}
|
||||
if err = tx.Commit(ctx); err != nil {
|
||||
return fmt.Errorf("commit missing failed")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user