-
Notifications
You must be signed in to change notification settings - Fork 32
🐛 Minor fixes for the function api #8376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
bisgaard-itis
merged 14 commits into
ITISFoundation:master
from
bisgaard-itis:further-fixes-for-function-api
Sep 17, 2025
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
225ed5d
add FunctionJobCreationTaskStatus enum to handle task status convertion
bisgaard-itis a20dfdd
cosmetic fix
bisgaard-itis ea1c223
clean up celery task states
bisgaard-itis ac29195
make run function tasks non-ephemeral
bisgaard-itis 7024459
cosmetic fix
bisgaard-itis 34d3da8
ensure all failure celery states end with
bisgaard-itis 4a92f01
add test for custom logic
bisgaard-itis a27b839
cleanup
bisgaard-itis 0448d48
pylint fixes
bisgaard-itis f4fb69f
Merge branch 'master' into further-fixes-for-function-api
bisgaard-itis 051e983
minor fix
bisgaard-itis 3a92c57
@pcrespov return FunctionJobCreationTaskStatus
bisgaard-itis aab8723
@pcrespov add log_context
bisgaard-itis f7e30dd
Merge branch 'master' into further-fixes-for-function-api
bisgaard-itis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
54 changes: 54 additions & 0 deletions
54
services/api-server/src/simcore_service_api_server/models/schemas/functions.py
This file contains hidden or 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,54 @@ | ||
| # pylint: disable=protected-access | ||
|
|
||
| from enum import StrEnum | ||
| from typing import Annotated, Final | ||
|
|
||
| from models_library.functions import FunctionID, FunctionJobCollectionID, FunctionJobID | ||
| from pydantic import BaseModel, ConfigDict, Field | ||
| from servicelib.celery.models import TaskState | ||
|
|
||
| _JOB_TASK_RUN_STATUS_PREFIX: Final[str] = "JOB_TASK_RUN_STATUS_" | ||
|
|
||
|
|
||
| class FunctionJobsListFilters(BaseModel): | ||
| """Filters for listing function jobs""" | ||
|
|
||
| function_id: Annotated[ | ||
| FunctionID | None, | ||
| Field( | ||
| description="Filter by function ID pattern", | ||
| ), | ||
| ] = None | ||
|
|
||
| function_job_ids: Annotated[ | ||
| list[FunctionJobID] | None, | ||
| Field( | ||
| description="Filter by function job IDs", | ||
| ), | ||
| ] = None | ||
|
|
||
| function_job_collection_id: Annotated[ | ||
| FunctionJobCollectionID | None, | ||
| Field( | ||
| description="Filter by function job collection ID", | ||
| ), | ||
| ] = None | ||
|
|
||
| model_config = ConfigDict( | ||
| extra="ignore", | ||
| ) | ||
|
|
||
|
|
||
| class FunctionJobCreationTaskStatus(StrEnum): | ||
| PENDING = f"{_JOB_TASK_RUN_STATUS_PREFIX}PENDING" | ||
| STARTED = f"{_JOB_TASK_RUN_STATUS_PREFIX}STARTED" | ||
| RETRY = f"{_JOB_TASK_RUN_STATUS_PREFIX}RETRY" | ||
| SUCCESS = f"{_JOB_TASK_RUN_STATUS_PREFIX}SUCCESS" | ||
| FAILURE = f"{_JOB_TASK_RUN_STATUS_PREFIX}FAILURE" | ||
bisgaard-itis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| NOT_YET_SCHEDULED = "JOB_TASK_NOT_YET_SCHEDULED" # api-server custom status | ||
| ERROR = "JOB_TASK_CREATION_FAILURE" # api-server custom status | ||
|
|
||
|
|
||
| assert {elm._name_ for elm in TaskState}.union({"NOT_YET_SCHEDULED", "ERROR"}) == { | ||
| elm._name_ for elm in FunctionJobCreationTaskStatus | ||
| } | ||
33 changes: 0 additions & 33 deletions
33
services/api-server/src/simcore_service_api_server/models/schemas/functions_filters.py
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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
83 changes: 83 additions & 0 deletions
83
services/api-server/tests/unit/service/test_service_function_jobs_task_client.py
This file contains hidden or 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,83 @@ | ||
| # pylint: disable=redefined-outer-name | ||
|
|
||
| from collections.abc import Callable | ||
|
|
||
| import pytest | ||
| from celery_library.errors import TaskNotFoundError | ||
| from faker import Faker | ||
| from models_library.products import ProductName | ||
| from models_library.progress_bar import ProgressReport | ||
| from models_library.users import UserID | ||
| from pytest_mock import MockerFixture, MockType | ||
| from servicelib.celery.models import TaskState, TaskStatus, TaskUUID | ||
| from servicelib.celery.task_manager import TaskManager | ||
| from simcore_service_api_server._service_function_jobs_task_client import ( | ||
| _celery_task_status, | ||
| ) | ||
| from simcore_service_api_server.models.schemas.functions import ( | ||
| FunctionJobCreationTaskStatus, | ||
| ) | ||
|
|
||
| _faker = Faker() | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| async def create_mock_task_manager( | ||
| mocker: MockerFixture, | ||
| ) -> Callable[[TaskStatus | Exception], MockType]: | ||
|
|
||
| def _(status_or_exception: TaskStatus | Exception) -> MockType: | ||
| mock_task_manager = mocker.Mock(spec=TaskManager) | ||
| if isinstance(status_or_exception, Exception): | ||
|
|
||
| async def _raise(*args, **kwargs): | ||
| raise status_or_exception | ||
|
|
||
| mock_task_manager.get_task_status.side_effect = _raise | ||
| else: | ||
| mock_task_manager.get_task_status.return_value = status_or_exception | ||
| return mock_task_manager | ||
|
|
||
| return _ | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "status_or_exception", | ||
| [ | ||
| TaskStatus( | ||
| task_uuid=TaskUUID(_faker.uuid4()), | ||
| task_state=state, | ||
| progress_report=ProgressReport(actual_value=3.14), | ||
| ) | ||
| for state in list(TaskState) | ||
| ] | ||
| + [TaskNotFoundError(task_id=_faker.uuid4())], | ||
| ) | ||
| @pytest.mark.parametrize("job_creation_task_id", [_faker.uuid4(), None]) | ||
| async def test_celery_status_conversion( | ||
| status_or_exception: TaskStatus | Exception, | ||
| job_creation_task_id: str | None, | ||
| create_mock_task_manager: Callable[[TaskStatus | Exception], MockType], | ||
| user_id: UserID, | ||
| product_name: ProductName, | ||
| ): | ||
|
|
||
| mock_task_manager = create_mock_task_manager(status_or_exception) | ||
|
|
||
| status = await _celery_task_status( | ||
| job_creation_task_id=job_creation_task_id, | ||
| task_manager=mock_task_manager, | ||
| user_id=user_id, | ||
| product_name=product_name, | ||
| ) | ||
|
|
||
| if job_creation_task_id is None: | ||
| assert status == FunctionJobCreationTaskStatus.NOT_YET_SCHEDULED | ||
| elif isinstance(status_or_exception, TaskNotFoundError): | ||
| assert status == FunctionJobCreationTaskStatus.ERROR | ||
| elif isinstance(status_or_exception, TaskStatus): | ||
| assert ( | ||
| status == FunctionJobCreationTaskStatus[status_or_exception.task_state.name] | ||
| ) | ||
| else: | ||
| pytest.fail("Unexpected test input") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.