Skip to content

Commit b01e479

Browse files
committed
add rpc method for getting jobs associated with user
1 parent 09a3650 commit b01e479

File tree

5 files changed

+32
-3
lines changed

5 files changed

+32
-3
lines changed

packages/models-library/src/models_library/api_schemas_rpc_async_jobs/async_jobs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class AsyncJobResult(BaseModel):
3535

3636
class AsyncJobGet(BaseModel):
3737
job_id: AsyncJobId
38-
task_name: str
38+
job_name: str
3939

4040

4141
class AsyncJobAbort(BaseModel):

packages/service-library/src/servicelib/rabbitmq/rpc_interfaces/storage/data_export.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
DataExportTaskStartInput,
77
)
88
from models_library.rabbitmq_basic_types import RPCMethodName
9+
from models_library.users import UserID
910
from pydantic import NonNegativeInt, TypeAdapter
1011

1112
from ... import RabbitMQRPCClient
@@ -26,3 +27,15 @@ async def start_data_export(
2627
)
2728
assert isinstance(result, AsyncJobGet)
2829
return result
30+
31+
32+
async def get_user_jobs(
33+
rabbitmq_rpc_client: RabbitMQRPCClient, *, user_id: UserID
34+
) -> list[AsyncJobGet]:
35+
result: list[AsyncJobGet] = await rabbitmq_rpc_client.request(
36+
STORAGE_RPC_NAMESPACE,
37+
_RPC_METHOD_NAME_ADAPTER.validate_python("get_user_jobs"),
38+
user_id=user_id,
39+
timeout_s=_DEFAULT_TIMEOUT_S,
40+
)
41+
return result

services/storage/src/simcore_service_storage/api/rpc/_data_export.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
DataExportTaskStartInput,
99
InvalidFileIdentifierError,
1010
)
11+
from models_library.users import UserID
1112
from servicelib.rabbitmq import RPCRouter
1213

1314
router = RPCRouter()
@@ -26,5 +27,12 @@ async def start_data_export(
2627
assert app # nosec
2728
return AsyncJobGet(
2829
job_id=uuid4(),
29-
task_name=", ".join(str(p) for p in paths.paths),
30+
job_name=", ".join(str(p) for p in paths.paths),
3031
)
32+
33+
34+
@router.expose()
35+
async def get_user_jobs(app: FastAPI, user_id: UserID) -> list[AsyncJobGet]:
36+
assert app # nosec
37+
assert user_id # nosec
38+
return [AsyncJobGet(job_id=uuid4(), job_name="myjob")]

services/storage/tests/unit/test_data_export.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,11 @@ async def test_get_data_export_result(rpc_client: RabbitMQRPCClient, faker: Fake
109109
rpc_client, rpc_namespace=STORAGE_RPC_NAMESPACE, job_id=_job_id
110110
)
111111
assert isinstance(result, AsyncJobResult)
112+
113+
114+
async def test_get_user_jobs(rpc_client: RabbitMQRPCClient, faker: Faker):
115+
result = await data_export.get_user_jobs(
116+
rpc_client, user_id=faker.pyint(min_value=1)
117+
)
118+
assert isinstance(result, list)
119+
assert all(isinstance(elm, AsyncJobGet) for elm in result)

services/web/server/tests/unit/with_dbs/03/test_storage_rpc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def side_effect(*args, **kwargs):
6161
@pytest.mark.parametrize(
6262
"backend_result_or_exception",
6363
[
64-
AsyncJobGet(job_id=AsyncJobId(_faker.uuid4()), task_name=_faker.text()),
64+
AsyncJobGet(job_id=AsyncJobId(_faker.uuid4()), job_name=_faker.text()),
6565
InvalidFileIdentifierError(file_id=Path("/my/file")),
6666
AccessRightError(user_id=_faker.pyint(min_value=0), file_id=Path("/my/file")),
6767
DataExportError(job_id=_faker.pyint(min_value=0)),

0 commit comments

Comments
 (0)