Skip to content

Service#

lit.sdk.services.service #

This module defines the Service abstract base class, representing a generic service within a system. It also defines the data structures for handling service actions and status.

This module is intended to be subclassed by other classes that implement specific behaviors for different services. The data structures provide a standard format for handling service-related information.

Service #

Bases: ABC

Abstract base class for managing services.

name = name instance-attribute #

The name of the service.

team = team instance-attribute #

The name of the team that owns the service.

__init__(team, name) #

Initializes a new instance of Service.

Parameters:

Name Type Description Default
team str

The name of the team that owns the service.

required
name str

The name of the service.

required

restart() abstractmethod #

Restarts the service.

Returns:

Name Type Description
ServiceActionStatus ServiceActionStatus

A dictionary containing the status of the operation.

Raises:

Type Description
NotImplementedError

If the method is not implemented by a subclass.

Examples:

>>> service = SomeServiceSubclass("contoso", "service_name")
>>> service.restart()
{'status': 'SUCCESS', 'message': 'Service restarted successfully.'}

start() abstractmethod #

Starts the service.

Returns:

Name Type Description
ServiceActionStatus ServiceActionStatus

A dictionary containing the status of the operation.

Raises:

Type Description
NotImplementedError

If the method is not implemented by a subclass.

Examples:

>>> service = SomeServiceSubclass("contoso", "service_name")
>>> service.start()
{'status': 'SUCCESS', 'message': 'Service started successfully.'}

status() abstractmethod #

Retrieves the status of the service.

Returns:

Name Type Description
ServiceStatus ServiceStatus

A dictionary containing the current status of the service.

Raises:

Type Description
NotImplementedError

If the method is not implemented by a subclass.

Examples:

>>> service = SomeServiceSubclass("contoso", "service_name")
>>> service.status()
{'name': 'service_name', 'active': 'active', 'status': 'running', 'started': 'Wed 2024-07-24 13:32:23 CDT', 'pid': 3687984, 'tasks': 5, 'memory': '3.3G'}

stop() abstractmethod #

Stops the service.

Returns:

Name Type Description
ServiceActionStatus ServiceActionStatus

A dictionary containing the status of the operation.

Raises:

Type Description
NotImplementedError

If the method is not implemented by a subclass.

Examples:

>>> service = SomeServiceSubclass("contoso", "service_name")
>>> service.stop()
{'status': 'SUCCESS', 'message': 'Service stopped successfully.'}

ServiceActionStatus #

Bases: TypedDict

Represents the status of a service action.

Examples:

>>> action_status: ServiceActionStatus = {
...     "status": "SUCCESS",
...     "message": "Service started successfully."
... }

message instance-attribute #

A descriptive message regarding the action's outcome.

status instance-attribute #

The result status of the action.

ServiceStatus #

Bases: TypedDict

Represents the status of a service.

Examples:

>>> service_status: ServiceStatus = {
...     "name": "my_service",
...     "active": "active",
...     "status": "running",
...     "started": "Wed 2024-07-24 13:32:23 CDT",
...     "pid": 3687984,
...     "tasks": 5,
...     "memory": "3.3G"
... }

active instance-attribute #

The active status of the service (e.g., 'active', 'inactive').

memory instance-attribute #

The memory usage of the service.

name instance-attribute #

The name of the service.

pid instance-attribute #

The process ID associated with the service.

started instance-attribute #

The timestamp when the service was started.

status instance-attribute #

The detailed status of the service (e.g., 'running', 'stopped').

tasks instance-attribute #

The number of tasks or threads the service is running.