Skip to content

Commit

Permalink
--amend
Browse files Browse the repository at this point in the history
  • Loading branch information
xjules committed Dec 11, 2023
1 parent 95e1fd0 commit 6717b93
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
12 changes: 12 additions & 0 deletions src/ert/scheduler/job.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import asyncio
import logging
from enum import Enum
from typing import TYPE_CHECKING

Expand All @@ -16,6 +17,8 @@
from ert.ensemble_evaluator._builder._realization import Realization
from ert.scheduler.scheduler import Scheduler

logger = logging.getLogger(__name__)


class State(str, Enum):
WAITING = "WAITING"
Expand Down Expand Up @@ -92,6 +95,15 @@ async def __call__(
await self._send(State.FAILED)
retries += 1
retry = retries < self._scheduler._max_submit
if retry:
message = f"Realization: {self.iens} failed, resubmitting"
logger.error(message)
else:
message = (
f"Realization: {self.iens} "
"failed after reaching max submit"
)
logger.warning(message)

except asyncio.CancelledError:
await self._send(State.ABORTING)
Expand Down
16 changes: 6 additions & 10 deletions tests/unit_tests/scheduler/test_scheduler.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import asyncio
import json
import shutil
from dataclasses import asdict
from pathlib import Path
from typing import Sequence
from unittest.mock import AsyncMock, patch

import pytest

Expand Down Expand Up @@ -114,11 +112,9 @@ async def test_cancel(tmp_path: Path, realization):
async def test_that_max_submit_was_reached(tmp_path: Path, realization):
step = create_bash_step("sleep 2; exit 1")
realization.forward_models = [step]
with patch("scheduler.Job.started.wait", new_callable=AsyncMock) as mock_wait:
sch = scheduler.Scheduler()
sch.add_realization(realization, callback_timeout=lambda _: None)
create_jobs_json(tmp_path, [step])
sch.add_dispatch_information_to_jobs_file()
scheduler_task = asyncio.create_task(sch.execute())
await scheduler_task
assert mock_wait.call_count == 2
sch = scheduler.Scheduler()
sch.add_realization(realization, callback_timeout=lambda _: None)
create_jobs_json(tmp_path, [step])
sch.add_dispatch_information_to_jobs_file()
scheduler_task = asyncio.create_task(sch.execute())
await scheduler_task

0 comments on commit 6717b93

Please sign in to comment.