artificial.adapter_common#

class ActionModulePlugin#
add_module(
module: ActionModule,
) None#
abstract async setup(
pctx: PluginContext,
) None#
class PluginContext(*args, **kwargs)#
abstract property alabPyBase: AlabPyBase#

Deprecated. Use AlabPyBase.from_config() instead.

abstract property artificial_api: ArtificialApi#

Artificial API methods.

abstract property assetStateReporter: AssetReporter#

Deprecated. Use lab.assets API instead.

abstract property config: AdapterProgramConfig#
abstract property experimental: ExperimentalApi#

Experimental API methods.

abstract property gql_session: AutoReconnectingAsyncClientSession#

GraphQL session connected to the alab instance

abstract property lab: LabApi#

Experimental API for reading and modifying a Lab.

abstract property raw_config: Config#
class ActionModule#
property artificial_api: ArtificialApi#

Artificial API for an action module.

async close() None#

Called when the adapter is shutting down.

static get_action_definitions(
module: Type | ActionModule,
) List[ActionDefinition]#
classmethod get_name() str#

Only needed for python 3.8. In 3.9 the name property can be a classmethod.

classmethod get_signature(
clean: bool = True,
) ServiceSignature#
property lab_api: LabApi#

Lab API for an action module.

property moduleRuntime: ActionModuleRuntime#
property module_runtime: ActionModuleRuntime#
property name: str#
property plugin_ctx: PluginContext#

Plugin context for an action module.

async setup(
runtime: ActionModuleRuntime,
) None#

Called on module initialization allowing module runtime preparation steps.

class ActionExecutionContext(*args, **kwargs)#
abstract property action: Action#

The protobuf message for this action.

abstract property auth: Dict[str, str]#

The authorization data for alab.

abstract property canceled: bool#

True if this action has been canceled and should terminate as soon as possible.

abstract property function: str#

Function name of this action.

abstract getRestoreData() str | None#

Return a previously stored restoreData if an instance of this action has not completed and the Adapter has restarted. Otherwise returns None and this is a fresh start of this action. If an action should be restorable, call this in the beginning of your action to switch between fresh start and restart.

abstract get_restore_data() str | None#

Return a previously stored restoreData if an instance of this action has not completed and the Adapter has restarted. Otherwise returns None and this is a fresh start of this action. If an action should be restorable, call this in the beginning of your action to switch between fresh start and restart.

abstract property job_id: str#

The job ID of the alab service.

abstract property moduleRuntime: ActionModuleRuntime#

Deprecated: Return the ActionModuleRuntime this ActionContext is related to.

abstract property module_runtime: ActionModuleRuntime#

Return the ActionModuleRuntime this ActionContext is related to.

abstract observeFinish(
awaitable: Coroutine[Any, Any, Message],
) None#

Spawn a task that waits for the given future to finish and then reports back completion or failure as the result of this action.

abstract property orgID: str#

Deprecated: Org ID of this action.

abstract property parameters: Dict[str, Any]#

The raw parameters of this action.

abstract property paused: bool#

True if this action is currently paused, false if it is running.

abstract persistRestoreData(restoreData: str) None#

Persist data to restore and continue this action after an Adapter restart.

abstract async persist_restore_data(restoreData: str) None#

Persist data to restore and continue this action after an Adapter restart.

abstract async reportCompleted(result: Message) None#

Report that the action has completed successfully.

abstract async reportFailed(error: Exception) None#

Report that the action has failed with an error.

abstract async reportPaused(paused: bool) None#

Report that the action was paused or resumed externally

abstract property sequenceID: str#

Deprecated: The sequence ID of this action

abstract property sequence_id: str#

The sequence ID of this action

abstract setAbortHandler(
handler: Callable[[], Coroutine[Any, Any, None]],
) None#

Set a handler to terminate this action as soon as possible. Note that this is different from asyncio task cancel which is used to shut down of the adapter and it is best to let a CancelledError throw.

abstract setPauseHandler(
handler: Callable[[bool], Coroutine[Any, Any, None]],
) None#

Set a handler to pause and resume this action.

abstract set_abort_handler(
handler: Callable[[], Coroutine[Any, Any, None]],
) None#

Set a handler to terminate this action as soon as possible. Note that this is different from asyncio task cancel which is used to shut down of the adapter and it is best to let a CancelledError throw.

abstract set_pause_handler(
handler: Callable[[bool], Coroutine[Any, Any, None]],
) None#

Set a handler to pause and resume this action.

abstract property url: str#

The URL of the alab service.

@action_modules(
*moduleTypes: Type[ActionModule],
) Callable[[Type[ActionModulePlugin]], Type[ActionModulePlugin]]#
@ability_name(
name: str,
) Callable[[Type[T]], Type[T]]#

Decorator for (Base)ActionModule to specify an ability name that applies to each of its @action methods.

class Health(*args, **kwargs)#
Message#

alias of HealthMessage

abstract async add_monitor(
id: str,
callback: Callable[[], Coroutine[None, None, HealthMessage]],
interval_s: float = 10.0,
grace_s: float = 2.0,
) None#

Sets a health status monitor for a given id. The given callback will be regularly called and is expected to return within the configured grace period, otherwise the invocation is canceled. If the callback does not return in time or raises an error the state is considered to be in error.

static error(
msg: str = '',
) HealthMessage#
abstract get_status() Dict[str, HealthMessage]#
static ok(msg: str = '') HealthMessage#
abstract async remove_monitor(id: str) None#

Removes the monitor with given id. Its callback will not be called anymore and its status does not contribute to the overall system status anymore. This can also be used to remove the remote health state, even if the monitor has not been added locally.

static warning(
msg: str = '',
) HealthMessage#