Skip to content

Commit

Permalink
fix: ensure noWorkerAssignedTime is reset when there is an assigned w…
Browse files Browse the repository at this point in the history
…orker

This is to avoid a possible case of where Fulfilled expectations where left with noWorkerAssignedTime being set..
  • Loading branch information
nytamin committed Mar 26, 2024
1 parent 4a72b61 commit c8266d6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,15 @@ export class TrackedExpectationAPI {
noAssignedWorkerReason = trackedExp.session.noAssignedWorkerReason
}

if (!trackedExp.noWorkerAssignedTime) trackedExp.noWorkerAssignedTime = Date.now()
if (!trackedExp.noWorkerAssignedTime) {
const now = Date.now()
this.logger.error(
`Setting trackedExp.noWorkerAssignedTime of "${expLabel(trackedExp)}" to ${now} (reason: ${
noAssignedWorkerReason.tech
})`
)
trackedExp.noWorkerAssignedTime = now
}

// Special case: When WAITING and no worker was assigned, return to NEW so that another worker might be assigned:
if (trackedExp.state === ExpectedPackageStatusAPI.WorkStatusState.WAITING) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,11 @@ export class TrackedWorkerAgents {
public async assignWorkerToSession(trackedExp: TrackedExpectation): Promise<void> {
const session: ExpectationStateHandlerSession | null = trackedExp.session
if (!session) throw new Error('ExpectationManager: Internal error: Session not set')
if (session.assignedWorker) return // A worker has already been assigned
if (session.assignedWorker) {
// A worker has already been assigned
trackedExp.noWorkerAssignedTime = null
return
}

if (!trackedExp.availableWorkers.size) {
session.noAssignedWorkerReason = { user: `No workers available`, tech: `No workers available` }
Expand Down

0 comments on commit c8266d6

Please sign in to comment.