Skip to content

Commit

Permalink
Avoid attempting to lock other deleted resources (#1835)
Browse files Browse the repository at this point in the history
* Avoid attempting to lock other deleted resources

* 'Fix' cyclomatic complexity warning
  • Loading branch information
evankanderson authored Dec 6, 2023
1 parent 1642ebc commit 5a1ad8d
Showing 1 changed file with 18 additions and 1 deletion.
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

0 comments on commit 5a1ad8d

Please sign in to comment.