2022-12-01 05:33:20 +00:00
|
|
|
# Copyright (c) 2022 Kyle Schouviller (https://github.com/kyle0654)
|
|
|
|
|
2023-03-03 06:02:00 +00:00
|
|
|
|
2024-07-03 16:20:35 +00:00
|
|
|
from invokeai.app.services.invocation_services import InvocationServices
|
2022-12-01 05:33:20 +00:00
|
|
|
|
2023-07-27 14:54:01 +00:00
|
|
|
|
2022-12-01 05:33:20 +00:00
|
|
|
class Invoker:
|
|
|
|
"""The invoker, used to execute invocations"""
|
|
|
|
|
|
|
|
services: InvocationServices
|
|
|
|
|
2023-03-03 06:02:00 +00:00
|
|
|
def __init__(self, services: InvocationServices):
|
2022-12-01 05:33:20 +00:00
|
|
|
self.services = services
|
|
|
|
self._start()
|
|
|
|
|
|
|
|
def __start_service(self, service) -> None:
|
|
|
|
# Call start() method on any services that have it
|
2023-03-03 06:02:00 +00:00
|
|
|
start_op = getattr(service, "start", None)
|
2022-12-01 05:33:20 +00:00
|
|
|
if callable(start_op):
|
|
|
|
start_op(self)
|
|
|
|
|
|
|
|
def __stop_service(self, service) -> None:
|
|
|
|
# Call stop() method on any services that have it
|
2023-03-03 06:02:00 +00:00
|
|
|
stop_op = getattr(service, "stop", None)
|
2022-12-01 05:33:20 +00:00
|
|
|
if callable(stop_op):
|
|
|
|
stop_op(self)
|
|
|
|
|
|
|
|
def _start(self) -> None:
|
|
|
|
"""Starts the invoker. This is called automatically when the invoker is created."""
|
2023-02-25 04:11:28 +00:00
|
|
|
for service in vars(self.services):
|
|
|
|
self.__start_service(getattr(self.services, service))
|
2022-12-01 05:33:20 +00:00
|
|
|
|
|
|
|
def stop(self) -> None:
|
|
|
|
"""Stops the invoker. A new invoker will have to be created to execute further."""
|
|
|
|
# First stop all services
|
|
|
|
for service in vars(self.services):
|
|
|
|
self.__stop_service(getattr(self.services, service))
|