-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(agent): add task to report status to the API (#539)
- Loading branch information
Showing
8 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
jobbergate-agent/jobbergate_agent/jobbergate/report_health.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from loguru import logger | ||
|
||
from jobbergate_agent.clients.cluster_api import backend_client as jobbergate_api_client | ||
from jobbergate_agent.utils.exception import JobbergateApiError | ||
from jobbergate_agent.utils.logging import log_error | ||
|
||
|
||
async def report_health_status(interval: int) -> None: | ||
"""Ping the API to report the agent's status.""" | ||
logger.debug("Reporting status to the API") | ||
with JobbergateApiError.handle_errors("Failed to report agent status", do_except=log_error): | ||
response = await jobbergate_api_client.put("jobbergate/clusters/status", params={"interval": interval}) | ||
response.raise_for_status() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import httpx | ||
import pytest | ||
import respx | ||
|
||
from jobbergate_agent.jobbergate.report_health import report_health_status | ||
from jobbergate_agent.settings import SETTINGS | ||
from jobbergate_agent.utils.exception import JobbergateApiError | ||
|
||
|
||
@pytest.mark.asyncio | ||
@pytest.mark.usefixtures("mock_access_token") | ||
async def test_report_health_status__success(): | ||
interval = 60 | ||
async with respx.mock: | ||
status_route = respx.put(f"{SETTINGS.BASE_API_URL}/jobbergate/clusters/status") | ||
status_route.mock(return_value=httpx.Response(status_code=202)) | ||
|
||
await report_health_status(interval) | ||
|
||
assert status_route.call_count == 1 | ||
assert dict(status_route.calls.last.request.url.params) == {"interval": str(interval)} | ||
|
||
|
||
@pytest.mark.asyncio | ||
@pytest.mark.usefixtures("mock_access_token") | ||
async def test_report_health_status__failure(): | ||
interval = 60 | ||
async with respx.mock: | ||
status_route = respx.put(f"{SETTINGS.BASE_API_URL}/jobbergate/clusters/status") | ||
status_route.mock(return_value=httpx.Response(status_code=500)) | ||
|
||
with pytest.raises(JobbergateApiError): | ||
await report_health_status(interval) | ||
|
||
assert status_route.call_count == 1 | ||
assert dict(status_route.calls.last.request.url.params) == {"interval": str(interval)} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters