Skip to content

feat: add task status endpoint (ERA-12690)#44

Open
JoshuaVulcan wants to merge 4 commits into
mainfrom
ERA-12690-impl
Open

feat: add task status endpoint (ERA-12690)#44
JoshuaVulcan wants to merge 4 commits into
mainfrom
ERA-12690-impl

Conversation

@JoshuaVulcan
Copy link
Copy Markdown
Contributor

@JoshuaVulcan JoshuaVulcan commented Feb 11, 2026

Summary

Adds get_task_status(task_id) to both ERClient (sync) and AsyncERClient (async) for polling background task status.

  • Endpoint: core/taskstatus/{task_id}/ (GET)
  • Returns: dict with task_id, status (PENDING/STARTED/SUCCESS/FAILURE), result, and location
  • Enables tracking async operations like GPX uploads and data exports

Test plan

  • 6 new sync tests in tests/sync_client/test_task_status.py
  • 6 new async tests in tests/async_client/test_task_status.py
  • All 102 tests pass (12 new + 90 existing)
  • Tests cover all task states (PENDING, STARTED, SUCCESS, FAILURE)
  • Tests verify correct URL construction
  • Tests cover error handling (404 Not Found)

Related

  • Jira: ERA-12690

Add get_task_status(task_id) to both ERClient (sync) and AsyncERClient
(async) for polling the status of background tasks.

Endpoint: core/taskstatus/{task_id}/

Returns a dict with:
- task_id: the task identifier
- status: PENDING | STARTED | SUCCESS | FAILURE
- result: task result data (null while pending/started)
- location: relative URL to the status endpoint

This enables clients to track the progress of async operations like
GPX uploads and data exports.

Includes 12 new tests across sync and async test suites covering
all task states, URL construction, and error handling.

Co-authored-by: Cursor <cursoragent@cursor.com>
@JoshuaVulcan JoshuaVulcan added autoreviewing PR is currently being auto-reviewed and removed autoreviewing PR is currently being auto-reviewed labels Feb 11, 2026
@JoshuaVulcan JoshuaVulcan requested a review from a team as a code owner February 12, 2026 01:54
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a get_task_status convenience API to both sync and async EarthRanger clients, along with new tests to validate status parsing, error handling, and URL construction.

Changes:

  • Add get_task_status(task_id) to ERClient and AsyncERClient.
  • Add sync tests covering PENDING/SUCCESS/FAILURE/STARTED, 404 handling, and URL construction.
  • Add async tests covering the same scenarios using respx/httpx.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
erclient/client.py Introduces get_task_status on both sync and async clients, delegating to existing _get logic.
tests/sync_client/test_task_status.py New sync unit tests using unittest.mock to validate request URL and returned data payload behavior.
tests/async_client/test_task_status.py New async unit tests using respx to validate request URL, response parsing, and NOT_FOUND error mapping.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@@ -0,0 +1,123 @@
"""Tests for get_task_status in the sync ERClient."""
import json
from unittest.mock import patch, MagicMock
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Comment on lines +2 to +19
import json
from unittest.mock import patch, MagicMock

import pytest


SERVICE_ROOT = "https://fake-site.erdomain.org/api/v1.0"
TASK_ID = "abc12345-def6-7890-ghij-klmnopqrstuv"


def _mock_response(json_data=None, status_code=200, ok=True):
"""Helper to build a mock requests.Response."""
resp = MagicMock()
resp.ok = ok
resp.status_code = status_code
resp.text = json.dumps(json_data) if json_data is not None else ""
resp.json.return_value = json_data
return resp
Comment on lines +118 to +123
def test_get_task_status_not_found(er_client):
from erclient.er_errors import ERClientNotFound
with patch.object(er_client._http_session, "get") as mock_get:
mock_get.return_value = _mock_response(status_code=404, ok=False)
with pytest.raises(ERClientNotFound):
er_client.get_task_status("nonexistent-task-id")
Comment on lines +115 to +125
@pytest.mark.asyncio
async def test_get_task_status_not_found(er_client):
from erclient.er_errors import ERClientNotFound
async with respx.mock(assert_all_called=False) as respx_mock:
respx_mock.get(
f"{SERVICE_ROOT}/core/taskstatus/nonexistent-task-id/"
).respond(httpx.codes.NOT_FOUND, json={"status": {"code": 404}})

with pytest.raises(ERClientNotFound):
await er_client.get_task_status("nonexistent-task-id")
await er_client.close()
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Comment on lines +8 to +9
SERVICE_ROOT = "https://fake-site.erdomain.org/api/v1.0"
TASK_ID = "abc12345-def6-7890-ghij-klmnopqrstuv"
Comment on lines +7 to +9
SERVICE_ROOT = "https://fake-site.erdomain.org/api/v1.0"
TASK_ID = "abc12345-def6-7890-ghij-klmnopqrstuv"

Comment thread erclient/client.py
Comment on lines +1625 to +1632
async def get_task_status(self, task_id):
"""
Get the status of an async background task.

:param task_id: the task ID returned by an async operation (e.g. GPX upload)
:return: dict with task_id, status, result, and location
"""
return await self._get(f'core/taskstatus/{task_id}/')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants