mirror of
https://github.com/clearml/clearml-server
synced 2025-01-31 10:56:48 +00:00
22e9c2b7eb
Fix obtaining events for tasks moved from private to public Fix assert_exists() to return company_origin if requested
53 lines
1.5 KiB
Python
53 lines
1.5 KiB
Python
from typing import Text, Sequence, Callable, Union, Type
|
|
|
|
from funcsigs import signature
|
|
from jsonmodels import models
|
|
|
|
from .apicall import APICall, APICallResult
|
|
from .endpoint import EndpointFunc, Endpoint
|
|
from .service_repo import ServiceRepo
|
|
|
|
|
|
__all__ = ["APICall", "endpoint"]
|
|
|
|
|
|
LegacyEndpointFunc = Callable[[APICall], None]
|
|
|
|
|
|
def endpoint(
|
|
name: Text,
|
|
min_version: Text = "1.0",
|
|
required_fields: Sequence[Text] = None,
|
|
request_data_model: Type[models.Base] = None,
|
|
response_data_model: Type[models.Base] = None,
|
|
validate_schema=False,
|
|
):
|
|
""" Endpoint decorator, used to declare a method as an endpoint handler """
|
|
|
|
def decorator(f: Union[EndpointFunc, LegacyEndpointFunc]) -> EndpointFunc:
|
|
# Backwards compatibility: support endpoints with both old-style signature (call) and new-style signature
|
|
# (call, company, request_model)
|
|
func = f
|
|
if len(signature(f).parameters) == 1:
|
|
# old-style
|
|
def adapter(call, *_, **__):
|
|
return f(call)
|
|
|
|
func = adapter
|
|
|
|
ServiceRepo.register(
|
|
Endpoint(
|
|
name=name,
|
|
func=func,
|
|
min_version=min_version,
|
|
required_fields=required_fields,
|
|
request_data_model=request_data_model,
|
|
response_data_model=response_data_model,
|
|
validate_schema=validate_schema,
|
|
)
|
|
)
|
|
|
|
return func
|
|
|
|
return decorator
|