Refactoring mock usage of IDs (task package)
parent
a688eb84b3
commit
3651350cc5
|
@ -2,9 +2,7 @@
|
|||
package mock
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
|
@ -125,7 +123,7 @@ func (s *Scheduler) ReleaseError(err error) {
|
|||
type DesiredState struct {
|
||||
mu sync.Mutex
|
||||
// Map of stringified task ID to last ID used for run.
|
||||
runIDs map[string]uint32
|
||||
runIDs map[string]uint64
|
||||
|
||||
// Map of stringified, concatenated task and platform ID, to runs that have been created.
|
||||
created map[string]backend.QueuedRun
|
||||
|
@ -135,7 +133,7 @@ var _ backend.DesiredState = (*DesiredState)(nil)
|
|||
|
||||
func NewDesiredState() *DesiredState {
|
||||
return &DesiredState{
|
||||
runIDs: make(map[string]uint32),
|
||||
runIDs: make(map[string]uint64),
|
||||
created: make(map[string]backend.QueuedRun),
|
||||
}
|
||||
}
|
||||
|
@ -148,8 +146,7 @@ func (d *DesiredState) CreateRun(_ context.Context, taskID platform.ID, now int6
|
|||
tid := taskID.String()
|
||||
d.runIDs[tid]++
|
||||
|
||||
runID := make([]byte, 4)
|
||||
binary.BigEndian.PutUint32(runID, d.runIDs[tid])
|
||||
runID := platform.ID(d.runIDs[tid])
|
||||
qr := backend.QueuedRun{
|
||||
TaskID: taskID,
|
||||
RunID: runID,
|
||||
|
@ -175,7 +172,7 @@ func (d *DesiredState) CreatedFor(taskID platform.ID) []backend.QueuedRun {
|
|||
|
||||
var qrs []backend.QueuedRun
|
||||
for _, qr := range d.created {
|
||||
if bytes.Equal(qr.TaskID, taskID) {
|
||||
if qr.TaskID == taskID {
|
||||
qrs = append(qrs, qr)
|
||||
}
|
||||
}
|
||||
|
@ -247,7 +244,7 @@ func (e *Executor) RunningFor(taskID platform.ID) []*RunPromise {
|
|||
|
||||
var rps []*RunPromise
|
||||
for _, rp := range e.running {
|
||||
if bytes.Equal(rp.Run().TaskID, taskID) {
|
||||
if rp.Run().TaskID == taskID {
|
||||
rps = append(rps, rp)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue