|
1 | 1 | package service
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "fmt" |
| 5 | + |
4 | 6 | "github.com/gemsorg/assignment/pkg/assignment"
|
5 | 7 | "github.com/gemsorg/assignment/pkg/authentication"
|
6 | 8 | "github.com/gemsorg/assignment/pkg/authorization"
|
@@ -59,9 +61,15 @@ func (s *service) GetAssignment(id string) (*assignment.Assignment, error) {
|
59 | 61 | }
|
60 | 62 |
|
61 | 63 | 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) |
65 | 73 |
|
66 | 74 | // Check if there's an external service registered for this task
|
67 | 75 | r, err := s.GetRegistration(a.JobID)
|
@@ -138,9 +146,15 @@ func (s *service) ValidateAssignment(a assignment.NewAssignment, set *assignment
|
138 | 146 | }
|
139 | 147 | }
|
140 | 148 |
|
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) |
144 | 158 |
|
145 | 159 | // Check if there's an external service registered for this task
|
146 | 160 | r, err := s.GetRegistration(a.JobID)
|
|
0 commit comments