labthings_fastapi.invocations

Invocation Model.

This module contains types used to describe an Invocation.

Attributes

InputT

OutputT

InvocationModel

A model to serialise Invocation objects when they are polled over HTTP.

Classes

InvocationStatus

The current status of an Invocation.

LogRecordModel

A model to serialise logging.LogRecord objects.

InvocationSummary

A model to represent Invocation objects over HTTP.

GenericInvocationModel

A model to serialise Invocation objects when they are polled over HTTP.

Module Contents

class labthings_fastapi.invocations.InvocationStatus(*args, **kwds)

Bases: enum.Enum

The current status of an Invocation.

PENDING = 'pending'

The Invocation has not yet been started.

RUNNING = 'running'

The Invocation is running in its thread.

COMPLETED = 'completed'

The Invocation finished successfully. A return value may be available.

CANCELLED = 'cancelled'

The Invocation was cancelled and has finished.

ERROR = 'error'

The Invocation terminated unexpectedly due to an error.

class labthings_fastapi.invocations.LogRecordModel(/, **data: Any)

Bases: pydantic.BaseModel

A model to serialise logging.LogRecord objects.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

model_config

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

message: str
levelname: str
levelno: int
lineno: int
filename: str
created: datetime.datetime
exception_type: str | None = None
traceback: str | None = None
classmethod generate_message(data: Any) Any

Ensure LogRecord objects have constructed their message.

Parameters:

data – The LogRecord or serialised log record data to process.

Returns:

The LogRecord, with a message constructed.

class labthings_fastapi.invocations.InvocationSummary(/, **data: Any)

Bases: pydantic.BaseModel

A model to represent Invocation objects over HTTP.

This version of the model does not include logs our action outputs, and is intended for use in endpoints that might list several invocations.

See GenericInvocationModel for the full representation, to be used in endpoints referring to one specific invocation.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

status: InvocationStatus
id: uuid.UUID
href: labthings_fastapi.middleware.url_for.URLFor
timeStarted: datetime.datetime | None
timeRequested: datetime.datetime | None
timeCompleted: datetime.datetime | None
labthings_fastapi.invocations.InputT
labthings_fastapi.invocations.OutputT
class labthings_fastapi.invocations.GenericInvocationModel(/, **data: Any)

Bases: InvocationSummary, Generic[InputT, OutputT]

A model to serialise Invocation objects when they are polled over HTTP.

The input and output models are generic parameters, to allow this model to be used for specific Actions. These are usually set to Any because the invocation endpoint is not specific to any one Action, and thus the types are not known in advance.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

input: InputT
output: OutputT
log: Sequence[LogRecordModel]
labthings_fastapi.invocations.InvocationModel

A model to serialise Invocation objects when they are polled over HTTP.