This repository was archived by the owner on Sep 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2758 from MycroftAI/refactor/enclosure-startup
Ensure messagebus is connected before reporting that the service is ready
Showing
4 changed files
with
78 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Copyright 2020 Mycroft AI Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from mycroft.services.util import start_message_bus_client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Copyright 2020 Mycroft AI Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from threading import Event | ||
from mycroft.messagebus.client import MessageBusClient | ||
from mycroft.configuration import Configuration | ||
from mycroft.util import create_daemon, create_echo_function | ||
from mycroft.util.log import LOG | ||
|
||
|
||
def start_message_bus_client(service, bus=None): | ||
"""Start the bus client daemon and wait for connection. | ||
Arguments: | ||
service (str): name of the service starting the connection | ||
bus (MessageBusClient): an instance of the Mycroft MessageBusClient | ||
Returns: | ||
A connected instance of the MessageBusClient | ||
""" | ||
# Create a client if one was not provided | ||
if bus is None: | ||
bus = MessageBusClient() | ||
# Configuration.set_config_update_handlers(bus) | ||
bus_connected = Event() | ||
bus.on('message', create_echo_function(service)) | ||
# Set the bus connected event when connection is established | ||
bus.once('open', bus_connected.set) | ||
create_daemon(bus.run_forever) | ||
|
||
# Wait for connection | ||
bus_connected.wait() | ||
LOG.info('Connected to messagebus') | ||
|
||
return bus |