Skip to content

Commit

Permalink
fix(api): increment job counter for worker when it starts a new job (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Mar 26, 2023
1 parent 3aa7b8a commit 55e44e8
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions api/onnx_web/worker/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,24 +355,14 @@ def submit(
**kwargs,
) -> None:
device_idx = self.get_next_device(needs_device=needs_device)
device = self.devices[device_idx].device
logger.info(
"assigning job %s to device %s: %s",
key,
device_idx,
self.devices[device_idx],
device,
)

# increment job count before recycling (why tho?)
device = self.devices[device_idx].device
if device in self.total_jobs:
self.total_jobs[device] += 1
else:
self.total_jobs[device] = 1

# recycle before attempting to run
logger.debug("job count for device %s: %s", device, self.total_jobs[device])
self.rlock()

# build and queue job
job = JobCommand(key, device, fn, args, kwargs)
self.pending_jobs.append(job)
Expand Down Expand Up @@ -439,6 +429,16 @@ def update_job(self, progress: ProgressCommand):
job for job in self.pending_jobs if job.name != progress.job
]

# increment job counter if this is the start of a new job
if progress.progress == 0:
if progress.device in self.total_jobs:
self.total_jobs[progress.device] += 1
else:
self.total_jobs[progress.device] = 1

logger.debug("updating job count for device %s: %s", progress.device, self.total_jobs[progress.device])

# check if the job has been cancelled
if progress.job in self.cancelled_jobs:
logger.debug(
"setting flag for cancelled job: %s on %s",
Expand Down

0 comments on commit 55e44e8

Please sign in to comment.