Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid attempting to lock other deleted resources #1835

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion internal/eea/eea.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func (e *EEA) AggregateMiddleware(h message.HandlerFunc) message.HandlerFunc {
}
}

// nolint:gocyclo // TODO: hacking in the TODO about foreign keys pushed this over the limit.
func (e *EEA) aggregate(msg *message.Message) (*message.Message, error) {
ctx := msg.Context()
inf, err := engine.ParseEntityEvent(msg)
Expand All @@ -91,13 +92,29 @@ func (e *EEA) aggregate(msg *message.Message) (*message.Message, error) {
Str("repository_id", repoID.String())

// We need to check that the resources still exist before attempting to lock them.
// TODO: handle artifact_id and pull_request_id or refactor this to remove the foreign keys.
// TODO: consider whether we need foreign key checks on the locks.
if _, err := e.querier.GetRepositoryByID(ctx, repoID); err != nil {
if errors.Is(err, sql.ErrNoRows) {
logger.Msg("Skipping event because repository no longer exists")
return nil, nil
}
}
if artifactID.Valid {
if _, err := e.querier.GetArtifactByID(ctx, artifactID.UUID); err != nil {
if errors.Is(err, sql.ErrNoRows) {
logger.Msg("Skipping event because artifact no longer exists")
return nil, nil
}
}
}
if pullRequestID.Valid {
if _, err := e.querier.GetPullRequestByID(ctx, pullRequestID.UUID); err != nil {
if errors.Is(err, sql.ErrNoRows) {
logger.Msg("Skipping event because pull request no longer exists")
return nil, nil
}
}
}

res, err := e.querier.LockIfThresholdNotExceeded(ctx, db.LockIfThresholdNotExceededParams{
Entity: entities.EntityTypeToDB(inf.Type),
Expand Down
Loading