Skip to content

Commit

Permalink
Merge pull request #94 from NERSC/cached-false
Browse files Browse the repository at this point in the history
Fix issue with jobs db requests
  • Loading branch information
cjh1 authored Dec 16, 2024
2 parents 5c8bc9d + 4f3d77a commit 8a155d4
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 45 deletions.
4 changes: 3 additions & 1 deletion src/sfapi_client/_async/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ async def _fetch_raw_state(
partition: Optional[str] = None,
sacct: Optional[bool] = False,
):
params = {"sacct": sacct}
# For now we are pass cached=False to ensure we don't
# break compatibility
params = {"sacct": sacct, "cached": False}

job_url = f"compute/jobs/{compute.name}"

Expand Down
5 changes: 1 addition & 4 deletions src/sfapi_client/_sync/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,10 +383,7 @@ def get(self, url: str, params: Dict[str, Any] = {}) -> httpx.Response:
stop=tenacity.stop_after_attempt(MAX_RETRY),
)
def post(
self,
url: str,
data: Dict[str, Any] = None,
json: Dict[str, Any] = None
self, url: str, data: Dict[str, Any] = None, json: Dict[str, Any] = None
) -> httpx.Response:
client = self._http_client()

Expand Down
4 changes: 3 additions & 1 deletion src/sfapi_client/_sync/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ def _fetch_raw_state(
partition: Optional[str] = None,
sacct: Optional[bool] = False,
):
params = {"sacct": sacct}
# For now we are pass cached=False to ensure we don't
# break compatibility
params = {"sacct": sacct, "cached": False}

job_url = f"compute/jobs/{compute.name}"

Expand Down
28 changes: 4 additions & 24 deletions tests/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from concurrent.futures import ThreadPoolExecutor
import time

from sfapi_client import Client
from sfapi_client.jobs import JobState
from sfapi_client.compute import Compute
from sfapi_client.jobs import JobSqueue
Expand Down Expand Up @@ -52,22 +51,13 @@ def test_complete_timeout(authenticated_client, test_job_path, test_machine):
job.complete(timeout=10)


@pytest.mark.api_dev
def test_job_monitor_check_request(
mocker,
dev_client_id,
dev_client_secret,
authenticated_client,
test_job_path,
test_machine,
dev_api_url,
dev_token_url,
):
with Client(
client_id=dev_client_id,
secret=dev_client_secret,
api_base_url=dev_api_url,
token_url=dev_token_url,
) as client:
with authenticated_client as client:
num_jobs = 10
_fetch_jobs = mocker.patch("sfapi_client._monitor._fetch_jobs")

Expand Down Expand Up @@ -122,24 +112,14 @@ def _jobs(*arg, **kwargs):
assert len(ids) == num_jobs


# We currently run this in api-dev as its a new feature deployed there
@pytest.mark.api_dev
def test_job_monitor_multiple_threads(
dev_client_id,
dev_client_secret,
authenticated_client,
test_job_path,
test_machine,
dev_api_url,
dev_token_url,
):
num_jobs = 5

with Client(
client_id=dev_client_id,
secret=dev_client_secret,
api_base_url=dev_api_url,
token_url=dev_token_url,
) as client:
with authenticated_client as client:
machine = client.compute(test_machine)

jobs = []
Expand Down
17 changes: 2 additions & 15 deletions tests/test_jobs_async.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest
import asyncio

from sfapi_client import AsyncClient
from sfapi_client.compute import AsyncCompute
from sfapi_client.jobs import AsyncJobSqueue, AsyncJobSacct, JobState

Expand Down Expand Up @@ -162,23 +161,11 @@ async def test_job_monitor_job_types(async_authenticated_client, mocker, test_ma
assert kwargs["job_type"] == AsyncJobSacct


# We currently run this in api-dev as its a new feature deployed there
@pytest.mark.api_dev
@pytest.mark.asyncio
async def test_job_monitor_gather(
dev_client_id,
dev_client_secret,
test_job_path,
test_machine,
dev_api_url,
dev_token_url,
async_authenticated_client, test_job_path, test_machine
):
async with AsyncClient(
client_id=dev_client_id,
secret=dev_client_secret,
api_base_url=dev_api_url,
token_url=dev_token_url,
) as client:
async with async_authenticated_client as client:
machine = await client.compute(test_machine)

submit_tasks = []
Expand Down

0 comments on commit 8a155d4

Please sign in to comment.