Skip to content

Commit

Permalink
track deleted and revoked job proposal counts (#10424)
Browse files Browse the repository at this point in the history
  • Loading branch information
eutopian authored Aug 31, 2023
1 parent d4609e9 commit 14edc7c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
2 changes: 2 additions & 0 deletions core/services/feeds/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ type JobProposalCounts struct {
Cancelled int64
Approved int64
Rejected int64
Deleted int64
Revoked int64
}

// toMetrics transforms JobProposalCounts into a map with float64 values for setting metrics
Expand Down
2 changes: 2 additions & 0 deletions core/services/feeds/orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,8 @@ SELECT
COUNT(*) filter (where job_proposals.status = 'pending' OR job_proposals.pending_update = TRUE) as pending,
COUNT(*) filter (where job_proposals.status = 'approved' AND job_proposals.pending_update = FALSE) as approved,
COUNT(*) filter (where job_proposals.status = 'rejected' AND job_proposals.pending_update = FALSE) as rejected,
COUNT(*) filter (where job_proposals.status = 'revoked' AND job_proposals.pending_update = FALSE) as revoked,
COUNT(*) filter (where job_proposals.status = 'deleted' AND job_proposals.pending_update = FALSE) as deleted,
COUNT(*) filter (where job_proposals.status = 'cancelled' AND job_proposals.pending_update = FALSE) as cancelled
FROM job_proposals;
`
Expand Down
8 changes: 6 additions & 2 deletions core/services/feeds/orm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,8 @@ func Test_ORM_CountJobProposalsByStatus(t *testing.T) {
fmID = createFeedsManager(t, orm)

// Set initial values for job proposal counts
wantApproved, wantRejected int64
wantPending, wantCancelled = int64(1), int64(1)
wantApproved, wantRejected, wantDeleted, wantRevoked int64
wantPending, wantCancelled = int64(1), int64(1)
)

// Create a pending job proposal.
Expand Down Expand Up @@ -604,6 +604,8 @@ func Test_ORM_CountJobProposalsByStatus(t *testing.T) {
assert.Equal(t, wantApproved, counts.Approved)
assert.Equal(t, wantRejected, counts.Rejected)
assert.Equal(t, wantCancelled, counts.Cancelled)
assert.Equal(t, wantDeleted, counts.Deleted)
assert.Equal(t, wantRevoked, counts.Revoked)

// Upsert the cancelled job proposal to rejected
// which changes pending_update to TRUE, but leaves status as
Expand All @@ -630,6 +632,8 @@ func Test_ORM_CountJobProposalsByStatus(t *testing.T) {
assert.Equal(t, wantApproved, counts.Approved)
assert.Equal(t, wantRejected, counts.Rejected)
assert.Equal(t, wantCancelled, counts.Cancelled)
assert.Equal(t, wantDeleted, counts.Deleted)
assert.Equal(t, wantRevoked, counts.Revoked)
}

func Test_ORM_ListJobProposalByManagersIDs(t *testing.T) {
Expand Down
8 changes: 8 additions & 0 deletions core/services/feeds/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,10 @@ func (s *service) DeleteJob(ctx context.Context, args *DeleteJobArgs) (int64, er
return 0, errors.Wrap(err, "DeleteProposal failed")
}

if err = s.observeJobProposalCounts(); err != nil {
return 0, err
}

return proposal.ID, nil
}

Expand Down Expand Up @@ -494,6 +498,10 @@ func (s *service) RevokeJob(ctx context.Context, args *RevokeJobArgs) (int64, er
return 0, errors.Wrap(err, "RevokeSpec failed")
}

if err = s.observeJobProposalCounts(); err != nil {
return 0, err
}

return proposal.ID, nil
}

Expand Down
3 changes: 3 additions & 0 deletions core/services/feeds/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,7 @@ func Test_Service_DeleteJob(t *testing.T) {
before: func(svc *TestService) {
svc.orm.On("GetJobProposalByRemoteUUID", approved.RemoteUUID).Return(&approved, nil)
svc.orm.On("DeleteProposal", approved.ID, mock.Anything).Return(nil)
svc.orm.On("CountJobProposalsByStatus").Return(&feeds.JobProposalCounts{}, nil)
},
args: args,
wantID: approved.ID,
Expand Down Expand Up @@ -956,6 +957,7 @@ answer1 [type=median index=0];
svc.orm.On("GetJobProposalByRemoteUUID", pendingProposal.RemoteUUID).Return(pendingProposal, nil)
svc.orm.On("GetLatestSpec", pendingSpec.JobProposalID).Return(pendingSpec, nil)
svc.orm.On("RevokeSpec", pendingSpec.ID, mock.Anything).Return(nil)
svc.orm.On("CountJobProposalsByStatus").Return(&feeds.JobProposalCounts{}, nil)
},
args: args,
wantID: pendingProposal.ID,
Expand All @@ -972,6 +974,7 @@ answer1 [type=median index=0];
Definition: defn,
}, nil)
svc.orm.On("RevokeSpec", pendingSpec.ID, mock.Anything).Return(nil)
svc.orm.On("CountJobProposalsByStatus").Return(&feeds.JobProposalCounts{}, nil)
},
args: args,
wantID: pendingProposal.ID,
Expand Down

0 comments on commit 14edc7c

Please sign in to comment.