|
6 | 6 | from pathlib import Path |
7 | 7 | from typing import Dict, List |
8 | 8 |
|
9 | | -from job_executor.adapter import job_service |
| 9 | +from job_executor.adapter import job_service, local_storage |
10 | 10 | from job_executor.config import environment |
11 | 11 | from job_executor.config.log import setup_logging, initialize_logging_thread |
12 | 12 | from job_executor.domain import rollback |
13 | | -from job_executor.exception import RollbackException, StartupException |
| 13 | +from job_executor.exception import ( |
| 14 | + RollbackException, |
| 15 | + StartupException, |
| 16 | + LocalStorageError, |
| 17 | +) |
14 | 18 | from job_executor.model import Job, Datastore |
15 | 19 | from job_executor.model.worker import Worker |
16 | 20 | from job_executor.worker import ( |
|
26 | 30 | NUMBER_OF_WORKERS = int(environment.get("NUMBER_OF_WORKERS")) |
27 | 31 | DYNAMIC_WORKER_THRESHOLD = int(environment.get("DYNAMIC_WORKER_THRESHOLD")) |
28 | 32 | DATASTORE_DIR = environment.get("DATASTORE_DIR") |
29 | | -INPUT_DIR = Path(environment.get("INPUT_DIR")) |
30 | 33 |
|
31 | 34 | datastore = None |
32 | 35 |
|
33 | 36 |
|
34 | | -def get_size_in_bytes(dataset_name: str) -> int: |
35 | | - tar_path = INPUT_DIR / f"{dataset_name}.tar" |
36 | | - if not tar_path.exists(): |
37 | | - logger.warning(f"Tar file not found: {tar_path}") |
38 | | - return 0 # or maybe rais exception |
39 | | - return os.path.getsize(tar_path) |
40 | | - |
41 | | - |
42 | 37 | def is_system_paused() -> bool: |
43 | 38 | """Return True if the system is paused, otherwise False.""" |
44 | 39 | maintenance_status = job_service.get_maintenance_status() |
@@ -248,7 +243,14 @@ def main(): |
248 | 243 | f" (worker, built, queued manager jobs)" |
249 | 244 | ) |
250 | 245 | for job in queued_worker_jobs: |
251 | | - job_size = get_size_in_bytes(job.dataset_name) |
| 246 | + job_size = local_storage.get_size_in_bytes(job.dataset_name) |
| 247 | + if job_size == 0: |
| 248 | + logger.info( |
| 249 | + f"{job.job_id} Failed to get the size of the dataset." |
| 250 | + ) |
| 251 | + raise LocalStorageError( |
| 252 | + "Failed to get size of the dataset" |
| 253 | + ) |
252 | 254 |
|
253 | 255 | if manager_state.can_spawn_new_worker(job_size): |
254 | 256 | _handle_worker_job(job, workers, logging_queue) |
|
0 commit comments