Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
e4ed2fa
add dummy functions section in webserver add rpc interface
bisgaard-itis Mar 19, 2025
4b49f93
introduce functions section in api server and expose ping endpoint
bisgaard-itis Mar 19, 2025
5b1b06b
fix minor issues and manual testing
bisgaard-itis Mar 19, 2025
f65dff1
Merge branch 'master' into 7348-add-dummy-functions-api
bisgaard-itis Mar 19, 2025
1a18bf2
add __init__ to functions domain
bisgaard-itis Mar 19, 2025
5004019
added functions section in api
bisgaard-itis Mar 19, 2025
a24b9e7
make pylint happy
bisgaard-itis Mar 19, 2025
e52bac8
Merge branch 'master' into 7348-add-dummy-functions-api
bisgaard-itis Mar 20, 2025
394587e
@pcrespov remove ping from oas
bisgaard-itis Mar 20, 2025
cb107a0
@sanderegg assert input @pcrespov annotate ping function
bisgaard-itis Mar 20, 2025
e29dd1b
fix relative imports
bisgaard-itis Mar 20, 2025
5d277a9
regenerate oas
bisgaard-itis Mar 20, 2025
f1050a1
add module decorator and app_setting
bisgaard-itis Mar 21, 2025
fc5fe09
Merge branch 'master' into 7348-add-dummy-functions-api
bisgaard-itis Mar 24, 2025
dcea149
Merge branch 'master' into 7348-add-dummy-functions-api
bisgaard-itis Mar 25, 2025
a27ae21
Merge branch 'master' into 7348-add-dummy-functions-api
bisgaard-itis Mar 26, 2025
1aa663e
Merge branch 'master' into 7348-add-dummy-functions-api
bisgaard-itis Mar 27, 2025
869f747
Merge branch 'master' into 7348-add-dummy-functions-api
bisgaard-itis Mar 28, 2025
d066273
fix import
bisgaard-itis Mar 28, 2025
df7b5d8
update openapi specs
bisgaard-itis Mar 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import logging

from models_library.api_schemas_webserver import WEBSERVER_RPC_NAMESPACE
from models_library.rabbitmq_basic_types import RPCMethodName
from pydantic import TypeAdapter

from .....logging_utils import log_decorator
from .....rabbitmq import RabbitMQRPCClient

_logger = logging.getLogger(__name__)


@log_decorator(_logger, level=logging.DEBUG)
async def ping(
rabbitmq_rpc_client: RabbitMQRPCClient,
) -> str:
result = await rabbitmq_rpc_client.request(
WEBSERVER_RPC_NAMESPACE,
TypeAdapter(RPCMethodName).validate_python("ping"),
)
assert isinstance(result, str) # nosec
return result
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from .routes import credits as _credits
from .routes import (
files,
functions,
health,
licensed_items,
meta,
Expand Down Expand Up @@ -44,6 +45,7 @@ def create_router(settings: ApplicationSettings):
router.include_router(
licensed_items.router, tags=["licensed-items"], prefix="/licensed-items"
)
router.include_router(functions.router, tags=["functions"], prefix="/functions")

# NOTE: multiple-files upload is currently disabled
# Web form to upload files at http://localhost:8000/v0/upload-form-view
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from typing import Annotated

from fastapi import APIRouter, Depends

from ...services_rpc.wb_api_server import WbApiRpcClient
from ..dependencies.webserver_rpc import (
get_wb_api_rpc_client,
)

router = APIRouter()


@router.post("/ping", include_in_schema=False)
async def ping(
wb_api_rpc: Annotated[WbApiRpcClient, Depends(get_wb_api_rpc_client)],
):
return await wb_api_rpc.ping()
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
from servicelib.rabbitmq.rpc_interfaces.resource_usage_tracker.errors import (
NotEnoughAvailableSeatsError,
)
from servicelib.rabbitmq.rpc_interfaces.webserver.functions.functions import (
ping as _ping,
)
from servicelib.rabbitmq.rpc_interfaces.webserver.licenses.licensed_items import (
checkout_licensed_item_for_wallet as _checkout_licensed_item_for_wallet,
)
Expand Down Expand Up @@ -194,6 +197,9 @@ async def release_licensed_item_for_wallet(
num_of_seats=licensed_item_checkout_get.num_of_seats,
)

async def ping(self) -> str:
return await _ping(self._client)


def setup(app: FastAPI, rabbitmq_rmp_client: RabbitMQRPCClient):
wb_api_rpc_client = WbApiRpcClient(_client=rabbitmq_rmp_client)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from .email.plugin import setup_email
from .exporter.plugin import setup_exporter
from .folders.plugin import setup_folders
from .functions.plugin import setup_functions
from .garbage_collector.plugin import setup_garbage_collector
from .groups.plugin import setup_groups
from .invitations.plugin import setup_invitations
Expand Down Expand Up @@ -133,6 +134,9 @@ def create_application() -> web.Application:
# folders
setup_folders(app)

# functions
setup_functions(app)

# projects
setup_projects(app)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from aiohttp import web
from fastapi import FastAPI
from models_library.api_schemas_webserver import WEBSERVER_RPC_NAMESPACE
from servicelib.rabbitmq import RPCRouter

from ..rabbitmq import get_rabbitmq_rpc_server

# this is the rpc interface exposed to the api-server
# this interface should call the service layer

router = RPCRouter()


@router.expose()
async def ping(app: FastAPI) -> str:
assert app
return "pong from webserver"


async def register_rpc_routes_on_startup(app: web.Application):
rpc_server = get_rabbitmq_rpc_server(app)
await rpc_server.register_router(router, WEBSERVER_RPC_NAMESPACE, app)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# the repository layer. Calls directly to the db (function table) should be done here.
# see e.g. licenses/_licensed_resources_repository.py file for an example
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This is where calls to the business logic is done.
# calls to the `projects` interface should be done here.
# calls to _repo.py should also be done here

from aiohttp import web
from models_library.users import UserID

from ..projects import projects_service
from ..projects.models import ProjectDict


# example function
async def get_project_from_function(
app: web.Application,
function_uuid: str,
user_id: UserID,
) -> ProjectDict:

return await projects_service.get_project_for_user(
app=app, project_uuid=function_uuid, user_id=user_id
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from aiohttp import web

from . import _controller_rpc


def setup_functions(app: web.Application):
app.on_startup.append(_controller_rpc.register_rpc_routes_on_startup)
Loading