Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Startup and shutdown events (prep for endorser updates) #1459

Merged
merged 2 commits into from
Oct 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions aries_cloudagent/core/conductor.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
from ..vc.ld_proofs.document_loader import DocumentLoader
from ..wallet.did_info import DIDInfo
from .dispatcher import Dispatcher
from .util import STARTUP_EVENT_TOPIC, SHUTDOWN_EVENT_TOPIC

LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -363,8 +364,14 @@ async def start(self) -> None:
except Exception:
LOGGER.exception("Error accepting mediation invitation")

# notify protcols of startup status
await self.root_profile.notify(STARTUP_EVENT_TOPIC, {})

async def stop(self, timeout=1.0):
"""Stop the agent."""
# notify protcols that we are shutting down
await self.root_profile.notify(SHUTDOWN_EVENT_TOPIC, {})

shutdown = TaskQueue()
if self.dispatcher:
shutdown.run(self.dispatcher.complete())
Expand Down
10 changes: 10 additions & 0 deletions aries_cloudagent/core/util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""Core utilities and constants."""

import re


CORE_EVENT_PREFIX = "acapy::core::"
STARTUP_EVENT_TOPIC = CORE_EVENT_PREFIX + "startup"
STARTUP_EVENT_PATTERN = re.compile(f"^{STARTUP_EVENT_TOPIC}?$")
SHUTDOWN_EVENT_TOPIC = CORE_EVENT_PREFIX + "shutdown"
SHUTDOWN_EVENT_PATTERN = re.compile(f"^{SHUTDOWN_EVENT_TOPIC}?$")
21 changes: 21 additions & 0 deletions aries_cloudagent/protocols/endorse_transaction/v1_0/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

from ....admin.request_context import AdminRequestContext
from ....connections.models.conn_record import ConnRecord
from ....core.event_bus import Event, EventBus
from ....core.profile import Profile
from ....core.util import STARTUP_EVENT_PATTERN, SHUTDOWN_EVENT_PATTERN
from ....indy.issuer import IndyIssuerError
from ....ledger.error import LedgerError
from ....messaging.models.base import BaseModelError
Expand Down Expand Up @@ -694,6 +697,24 @@ async def transaction_write(request: web.BaseRequest):
return web.json_response(tx_completed.serialize())


def register_events(event_bus: EventBus):
"""Subscribe to any events we need to support."""
event_bus.subscribe(STARTUP_EVENT_PATTERN, on_startup_event)
event_bus.subscribe(SHUTDOWN_EVENT_PATTERN, on_shutdown_event)


async def on_startup_event(profile: Profile, event: Event):
"""Handle any events we need to support."""
print(">>> TODO Received STARTUP event")
pass


async def on_shutdown_event(profile: Profile, event: Event):
"""Handle any events we need to support."""
print(">>> TODO Received SHUTDOWN event")
pass


async def register(app: web.Application):
"""Register routes."""

Expand Down