-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
previously the notifer would attempt to create notifications for the same update operation if no affected manifests were discovered. with this patch we book keep the update operations we encountered and short circuit the processing of notifications which do not produce affected manifests. a receipt in "delivered" status is written to the database directly for update operations that do not produce affected manifests. this effectively removes them from subsequent processing and avoides any delivery attempts. Signed-off-by: ldelossa <ldelossa@redhat.com>
- Loading branch information
Showing
10 changed files
with
134 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package postgres | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/jackc/pgx/v4/pgxpool" | ||
"github.com/quay/clair/v4/notifier" | ||
) | ||
|
||
func putReceipt(ctx context.Context, pool *pgxpool.Pool, updater string, r notifier.Receipt) error { | ||
const ( | ||
insertNotification = `INSERT INTO notification (id) VALUES ($1);` | ||
insertReceipt = `INSERT INTO receipt (notification_id, uo_id, status, ts) VALUES ($1, $2, $3, CURRENT_TIMESTAMP);` | ||
insertUpdateOperation = ` | ||
INSERT INTO notifier_update_operation (updater, uo_id, ts) | ||
VALUES ($1, $2, CURRENT_TIMESTAMP) | ||
` | ||
) | ||
tx, err := pool.Begin(ctx) | ||
if err != nil { | ||
return fmt.Errorf("failed to create tx: %v", err) | ||
} | ||
defer tx.Rollback(ctx) | ||
|
||
tag, err := tx.Exec(ctx, insertNotification, r.NotificationID) | ||
if err != nil { | ||
return fmt.Errorf("failed to insert notification id: %v", err) | ||
} | ||
if tag.RowsAffected() == 0 { | ||
return fmt.Errorf("insert of notification id had no effect") | ||
} | ||
|
||
tag, err = tx.Exec(ctx, insertUpdateOperation, updater, r.UOID) | ||
if err != nil { | ||
return fmt.Errorf("failed to insert update operation id: %v", err) | ||
} | ||
if tag.RowsAffected() == 0 { | ||
return fmt.Errorf("insert of update operation had no effect") | ||
} | ||
|
||
tag, err = tx.Exec(ctx, | ||
insertReceipt, | ||
r.NotificationID, | ||
r.UOID, | ||
r.Status, | ||
) | ||
if err != nil { | ||
return fmt.Errorf("failed to insert receipt: %v", err) | ||
} | ||
if tag.RowsAffected() == 0 { | ||
return fmt.Errorf("insert of receipt had no effect") | ||
} | ||
err = tx.Commit(ctx) | ||
if err != nil { | ||
return fmt.Errorf("failed to commit tx: %v", err) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters