Skip to content
Draft
Show file tree
Hide file tree
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
42 changes: 39 additions & 3 deletions cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ def main() -> None:
worker_info = info.sys.collect()

while True:
container = None
job_id = None
path_job = None

try:
container = None
jobs = api_worker.fetch_jobs(
limit=1,
cpu_cores=worker_info.sys.cores,
Expand Down Expand Up @@ -177,8 +180,41 @@ def main() -> None:
else:
raise e

logger.info(f"Job {job_id} finished")
shutil.rmtree(path_job)
finally:
# Clean up resources after successful job run AND upload
if job_id:
logger.info(f"Cleaning up job {job_id}")

# Clean up Docker container
if container:
try:
if container.status == "running":
logger.info(f"Stopping running container for job {job_id}")
container.stop()
except Exception as e:
logger.warning(
f"Failed to stop container for job {job_id}: {e}"
)

try:
logger.info(f"Removing container for job {job_id}")
container.remove()
except Exception as e:
logger.warning(
f"Failed to remove container for job {job_id}: {e}"
)

# Clean up job directory
if path_job and path_job.exists():
try:
logger.info(f"Removing job directory {path_job}")
shutil.rmtree(path_job)
except Exception as e:
logger.warning(
f"Failed to clean up job directory {path_job}: {e}"
)

logger.info(f"Job {job_id} cleanup completed")


if __name__ == "__main__":
Expand Down
5 changes: 4 additions & 1 deletion fetcher/api/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
# ...existing code...
from . import builder as builder
from . import model as model
from . import token as token
from . import worker as worker
1 change: 0 additions & 1 deletion fetcher/docker/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
# ...existing code...
2 changes: 1 addition & 1 deletion fetcher/info/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# ...existing code...
from . import sys as sys
2 changes: 1 addition & 1 deletion fetcher/io/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# ...existing code...
from . import files as files
3 changes: 2 additions & 1 deletion fetcher/status/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# ...existing code...
from . import pinger as pinger
from . import status as status
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "fetcher"
version = "0.3.0"
version = "0.4.0"
description = "Job fetcher for workers of DECODE OpenCloud."
authors = ["Arthur Jaques <arthur.jaques@hispeed.ch>"]
readme = "README.md"
Expand Down
Loading
Loading