diff --git a/src/ert/scheduler/lsf_driver.py b/src/ert/scheduler/lsf_driver.py index e3769f8c94f..e2c85829dbc 100644 --- a/src/ert/scheduler/lsf_driver.py +++ b/src/ert/scheduler/lsf_driver.py @@ -11,6 +11,7 @@ Awaitable, Callable, Dict, + List, Mapping, MutableMapping, Optional, @@ -100,8 +101,7 @@ async def run_with_retries( try: await func() return - except (asyncio.CancelledError, IndexError) as e: - logger.error(e) + except (asyncio.CancelledError, RuntimeError): await asyncio.sleep(self._retry_sleep_period) raise RuntimeError(error_msg) @@ -116,18 +116,33 @@ async def submit( async def _submit_once( self, iens: int, executable: str, /, *args: str, cwd: str, job_name: str ) -> None: - process = await asyncio.create_subprocess_exec( - self._bsub_cmd, + bsub_with_args: List[str] = [ + str(self._bsub_cmd), "-J", job_name, executable, - cwd, + ] + process = await asyncio.create_subprocess_exec( + *bsub_with_args, + cwd=cwd, stdout=asyncio.subprocess.PIPE, + stderr=asyncio.subprocess.PIPE, ) - job_id, _ = await process.communicate() - job_id_ = ( - job_id.decode("utf-8").strip().replace("<", "").replace(">", "").split()[1] - ) + job_id, stderr = await process.communicate() + try: + job_id_ = ( + job_id.decode("utf-8") + .strip() + .replace("<", "") + .replace(">", "") + .split()[1] + ) + except IndexError as err: + logger.error( + f"Command \"{' '.join(bsub_with_args)}\" failed with error message: {stderr.decode()}" + ) + raise RuntimeError from err + (Path(cwd) / LSF_JSON).write_text( json.dumps({"job_id": job_id_}), encoding="utf-8" ) diff --git a/tests/integration_tests/scheduler/test_lsf_driver.py b/tests/integration_tests/scheduler/test_lsf_driver.py index c7d38e05c44..59707cb13fc 100644 --- a/tests/integration_tests/scheduler/test_lsf_driver.py +++ b/tests/integration_tests/scheduler/test_lsf_driver.py @@ -31,3 +31,19 @@ async def test_submit_poll_and_kill(): with contextlib.suppress(asyncio.CancelledError): await poll_task + + +@pytest.mark.timeout(5) +@pytest.mark.requires_lsf +async def test_job_name(): + driver = LsfDriver() + iens: int = 0 + await driver.submit(iens, "sleep 99", cwd=".", job_name="my_job_name") + jobid = driver._iens2jobid[iens] + bjobs_process = await asyncio.create_subprocess_exec( + "bjobs", + jobid, + stdout=asyncio.subprocess.PIPE, + ) + stdout, _ = await bjobs_process.communicate() + assert "my_job_name" in stdout.decode()