Skip to content
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
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/config.json
*.egginfo
*.egg-info
build
dist
.pytest_cache
.pytest_cache
__pycache__
11 changes: 8 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,22 @@ ENV OVOS_CONFIG_BASE_FOLDER=neon
ENV OVOS_CONFIG_FILENAME=diana.yaml
ENV OVOS_DEFAULT_CONFIG=/opt/neon/diana.yaml
ENV XDG_CONFIG_HOME=/config
ENV HEALTHCHECK_PORT=8000
Comment thread
NeonDaniel marked this conversation as resolved.

COPY docker_overlay/ /

RUN apt-get update && \
apt-get install -y \
gcc \
curl \
jq \
python3 \
python3-dev \
&& pip install wheel

ADD . /neon_api_proxy
COPY . /neon_api_proxy
WORKDIR /neon_api_proxy
RUN pip install .
RUN pip install --no-cache-dir .

CMD ["neon_api_proxy"]
HEALTHCHECK CMD "/opt/neon/healthcheck.sh"
CMD ["neon_api_proxy"]
37 changes: 37 additions & 0 deletions docker_overlay/opt/neon/healthcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash
# NEON AI (TM) SOFTWARE, Software Development Kit & Application Development System
# All trademark and other rights reserved by their respective owners
# Copyright 2008-2025 Neongecko.com Inc.
# BSD-3
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from this
# software without specific prior written permission.
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

port="${HEALTHCHECK_PORT:-8000}"
# Perform the health check using curl
resp_content=$(curl -s http://localhost:${port}/status)
status=$(echo "${resp_content}" | jq -r '.status')
if [ "${status}" == "Ready" ]; then
exit 0 # Success
else
echo "Health check failed with response: ${resp_content}" >&2
exit 1 # Failure
fi
7 changes: 7 additions & 0 deletions neon_api_proxy/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from os import environ
from ovos_utils import wait_for_exit_signal
from ovos_utils.log import init_service_logger
from neon_utils.process_utils import start_health_check_server

from neon_api_proxy.api_connector import NeonAPIMQConnector
from neon_api_proxy.controller import NeonAPIProxyController
Expand All @@ -43,6 +45,11 @@ def run_mq_handler():
connector = NeonAPIMQConnector(config=None,
service_name='neon_api_connector',
proxy=proxy)
if status_port := environ.get("HEALTHCHECK_PORT"):
start_health_check_server(
connector.status,
int(status_port),
connector.check_health)
connector.run()
wait_for_exit_signal()

Expand Down
21 changes: 19 additions & 2 deletions neon_api_proxy/api_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

from typing import Optional
from ovos_utils.log import LOG
from ovos_utils.process_utils import ProcessStatus
from neon_mq_connector.utils.network_utils import b64_to_dict, dict_to_b64
from neon_mq_connector.connector import MQConnector

Expand All @@ -48,10 +49,17 @@ def __init__(self, config: Optional[dict], service_name: str,
:param service_name: name of the service instance
"""
super().__init__(config, service_name)

self.status = ProcessStatus(self.service_name)
self.status.set_alive()
self.vhost = '/neon_api'
self.proxy = proxy

def check_health(self) -> bool:
if not MQConnector.check_health(self):
self.status.set_error("MQConnector health check failed")
return False
return self.status.check_ready()

def handle_api_input(self,
channel: pika.channel.Channel,
method: pika.spec.Basic.Deliver,
Expand Down Expand Up @@ -126,10 +134,19 @@ def extract_agent_tokens(msg_data: dict) -> dict:

def handle_error(self, thread, exception):
LOG.error(f"{exception} occurred in {thread}")
LOG.info(f"Restarting Consumers")
LOG.info("Restarting Consumers")
self.stop()
self.run()

def stop(self):
self.status.set_stopping()
MQConnector.stop(self)

def run(self):
MQConnector.run(self)
LOG.info("API Connector is running")
self.status.set_ready()

def pre_run(self, **kwargs):
self.register_consumer("neon_api_consumer", self.vhost,
'neon_api_input', self.handle_api_input,
Expand Down
2 changes: 1 addition & 1 deletion requirements/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
requests-cache~=0.6,>=0.6.4
requests~=2.20
neon-utils[network,sentry]~=1.0
neon-utils[network,sentry]~=1.0, >=1.12.2a2
ovos-utils>=0.0.31,<0.2.0
ovos-config~=0.1
neon-mq-connector~=0.8,>=0.8.1a3
Loading