Skip to content

Commit 4afc4f6

Browse files
committed
Fix assignment limit settings
1 parent 2e5c905 commit 4afc4f6

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

pkg/assignment/assignment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (a NewAssignment) IsAllowed(set *Settings) (bool, error) {
5656
}
5757

5858
// We reached the limit of the total assignment for the job and worker
59-
if set.Limit != 0 && set.Limit == a.WorkerAssignmentCount {
59+
if set.Limit != 0 && a.WorkerAssignmentCount >= set.Limit {
6060
return false, JobLimitReached{}
6161
}
6262

pkg/service/service.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package service
22

33
import (
4+
"fmt"
5+
46
"github.com/gemsorg/assignment/pkg/assignment"
57
"github.com/gemsorg/assignment/pkg/authentication"
68
"github.com/gemsorg/assignment/pkg/authorization"
@@ -59,9 +61,15 @@ func (s *service) GetAssignment(id string) (*assignment.Assignment, error) {
5961
}
6062

6163
func (s *service) CreateAssignment(a assignment.NewAssignment, set *assignment.Settings) (*assignment.Assignment, error) {
62-
// Get worker's assignment for this job
63-
assigned, err := s.store.WorkerAlreadyAssigned(a.JobID, a.WorkerID)
64-
a.WorkerAlreadyAssigned = assigned
64+
// Set worker's assignment count and check if they have an active assignment
65+
assignments, err := s.GetAssignments(assignment.Params{
66+
WorkerID: fmt.Sprintf("%d", a.WorkerID),
67+
JobID: fmt.Sprintf("%d", a.JobID),
68+
})
69+
for _, as := range assignments {
70+
a.WorkerAlreadyAssigned = as.Status == string(assignment.Active)
71+
}
72+
a.WorkerAssignmentCount = len(assignments)
6573

6674
// Check if there's an external service registered for this task
6775
r, err := s.GetRegistration(a.JobID)
@@ -138,9 +146,15 @@ func (s *service) ValidateAssignment(a assignment.NewAssignment, set *assignment
138146
}
139147
}
140148

141-
// Get worker's assignment for this job
142-
assigned, err := s.store.WorkerAlreadyAssigned(a.JobID, a.WorkerID)
143-
a.WorkerAlreadyAssigned = assigned
149+
// Set worker's assignment count and check if they have an active assignment
150+
assignments, err := s.GetAssignments(assignment.Params{
151+
WorkerID: fmt.Sprintf("%d", a.WorkerID),
152+
JobID: fmt.Sprintf("%d", a.JobID),
153+
})
154+
for _, as := range assignments {
155+
a.WorkerAlreadyAssigned = as.Status == string(assignment.Active)
156+
}
157+
a.WorkerAssignmentCount = len(assignments)
144158

145159
// Check if there's an external service registered for this task
146160
r, err := s.GetRegistration(a.JobID)

0 commit comments

Comments
 (0)