From 14edc7c6549bf77296b572bae0401baf8b1dd0e3 Mon Sep 17 00:00:00 2001 From: Margaret Ma Date: Thu, 31 Aug 2023 13:10:19 -0400 Subject: [PATCH] track deleted and revoked job proposal counts (#10424) --- core/services/feeds/models.go | 2 ++ core/services/feeds/orm.go | 2 ++ core/services/feeds/orm_test.go | 8 ++++++-- core/services/feeds/service.go | 8 ++++++++ core/services/feeds/service_test.go | 3 +++ 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/core/services/feeds/models.go b/core/services/feeds/models.go index 345919d4ad8..1a47f9f5c55 100644 --- a/core/services/feeds/models.go +++ b/core/services/feeds/models.go @@ -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 diff --git a/core/services/feeds/orm.go b/core/services/feeds/orm.go index dd04446bce9..b0b0bb38b55 100644 --- a/core/services/feeds/orm.go +++ b/core/services/feeds/orm.go @@ -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; ` diff --git a/core/services/feeds/orm_test.go b/core/services/feeds/orm_test.go index 0ff60188008..5294028b352 100644 --- a/core/services/feeds/orm_test.go +++ b/core/services/feeds/orm_test.go @@ -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. @@ -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 @@ -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) { diff --git a/core/services/feeds/service.go b/core/services/feeds/service.go index ca0dcbb06cc..429b47b41a6 100644 --- a/core/services/feeds/service.go +++ b/core/services/feeds/service.go @@ -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 } @@ -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 } diff --git a/core/services/feeds/service_test.go b/core/services/feeds/service_test.go index 48fefd35daf..4f92cd81b23 100644 --- a/core/services/feeds/service_test.go +++ b/core/services/feeds/service_test.go @@ -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, @@ -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, @@ -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,