Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
from miniray.lib.statsd_helpers import statsd
from miniray.lib.helpers import (
Limits, error_desc, GB_TO_BYTES, MAX_WORKER_LOOP_SECONDS, TASK_TIMEOUT_GRACE_SECONDS, JOB_CACHE_SIZE,
get_exception_details,
)
from miniray.lib.uv import sync_venv_cache, cleanup_venvs, populate_venv_cache_from_disk, pycache_dir_for_venv
from miniray.executor import (
Expand Down Expand Up @@ -285,7 +286,7 @@ def _reap(self, exiting=False) -> bool:
if self._kill_deadline is None:
t0 = time.perf_counter()
self.proc.poll()
if self.proc.returncode is None and not self._timed_out:
if self.proc.returncode is None and not self._timed_out and self._error is None:
self.reap_timings['poll'] = time.perf_counter() - t0
return False # still running
cgroup_kill(self.cgroup_name)
Expand Down Expand Up @@ -318,6 +319,8 @@ def _reap(self, exiting=False) -> bool:
self.reap_timings['result'] = time.perf_counter() - t0

# Determine result/error state
if self._error is not None:
return True
if self._timed_out:
self._error = ("TimeoutError", f"TimeoutError: task timed out after {self.limits.timeout_seconds} seconds")
elif self.proc.returncode != 0 and exiting:
Expand All @@ -332,9 +335,11 @@ def _reap(self, exiting=False) -> bool:

return True

def check_done(self, exiting=False) -> bool:
def check_done(self, exiting=False, error: Exception | None = None) -> bool:
self.reap_timings = {}
if not self._reaped:
if error is not None:
self._error = get_exception_details(error)
if self._reap(exiting):
self._reaped = True
self.finish(exiting)
Expand Down Expand Up @@ -705,6 +710,7 @@ def main():
last_init_timings = task.init_timings
except Exception as e:
fatal_error = e
raise
finally:
# send sigterm to all remaining processes
for proc in procs.values():
Expand All @@ -714,14 +720,11 @@ def main():
# wait for tasks to finish
while any(procs.values()):
for i, proc in procs.items():
if proc and proc.check_done(exiting=True):
if proc and proc.check_done(exiting=True, error=fatal_error):
procs[i] = None
time.sleep(1)

if fatal_error is not None:
raise fatal_error
else:
print(f"[worker] exited due to signal: {sigterm_handler.raised}")
print(f"[worker] exited due to signal: {sigterm_handler.raised}")


if __name__ == '__main__':
Expand Down
Loading