-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor server startup and configuration
This commit refactors the server startup and configuration in the `cli.py` file. It removes unnecessary imports and logging configurations. The server now starts three services in separate threads: RabbitMQ, SocketIO, and discovery. The `start_services` function is introduced to handle the initialization of these services. Additionally, error handling is added to catch any exceptions that may occur during the startup process.
- Loading branch information
Showing
5 changed files
with
69 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,74 @@ | ||
#!/usr/bin/env python3 | ||
import time | ||
import os | ||
import logging | ||
|
||
from common.Configberry import Configberry | ||
|
||
configberry = Configberry() | ||
|
||
environment = configberry.config.get("SERVIDOR", "environment", fallback="production") | ||
|
||
# configuro logger segun ambiente | ||
if environment == 'development': | ||
print("* * * * * Modo de desarrollo * * * * *") | ||
logging.basicConfig(level=logging.DEBUG) | ||
else: | ||
print("@ @ @ @ @ Modo de producción @ @ @ @ @") | ||
logging.basicConfig(level=logging.WARNING) | ||
|
||
import os, asyncio | ||
import threading | ||
|
||
from common.fiscalberry_logger import getLogger | ||
logger = getLogger() | ||
|
||
|
||
from common.Configberry import Configberry | ||
configberry = Configberry() | ||
|
||
|
||
# importo el modulo que se encarga de la comunicacion con el servidor | ||
from common.rabbit_mq_consumer import RabbitMQConsumer | ||
from common.discover import send_discover_in_thread | ||
import asyncio | ||
|
||
|
||
def startRabbit(): | ||
from common.rabbit_mq_consumer import RabbitMQConsumer | ||
|
||
def start(): | ||
logger.info("Iniciando Fiscalberry Server") | ||
|
||
uuid = configberry.config.get("SERVIDOR", "uuid") | ||
host = configberry.config.get("RabbitMq", "host", fallback="localhost") | ||
port = configberry.config.get("RabbitMq", "port", fallback="5672") | ||
user = configberry.config.get("RabbitMq", "user", fallback="guest") | ||
password = configberry.config.get("RabbitMq", "password", fallback="guest") | ||
#send_discover_in_thread() | ||
|
||
rb = RabbitMQConsumer(host, port, user, password, uuid) | ||
# Inside the while loop | ||
rb.start() | ||
logger.warning("Termino ejecucion de server socketio?.. reconectando en 5s") | ||
|
||
|
||
def startSocketio(): | ||
from common.fiscalberry_sio import FiscalberrySio | ||
serverUrl = configberry.config.get("SERVIDOR", "sio_host", fallback="") | ||
uuid = configberry.config.get("SERVIDOR", "uuid") | ||
sio = FiscalberrySio(serverUrl, uuid) | ||
sio.start_print_server() | ||
logger.warning("Termino ejecucion de server socketio?.. reconectando en 5s") | ||
|
||
|
||
def discover(): | ||
send_discover_in_thread() | ||
logger.info("Discover enviado") | ||
|
||
|
||
while True: | ||
def start_services(): | ||
logger.info("Iniciando Fiscalberry Server") | ||
|
||
# iniciar en 3 threads distintos los servicios | ||
discover_thread = threading.Thread(target=discover) | ||
socketio_thread = threading.Thread(target=startSocketio) | ||
rabbit_thread = threading.Thread(target=startRabbit) | ||
|
||
discover_thread.start() | ||
socketio_thread.start() | ||
rabbit_thread.start() | ||
|
||
sio = RabbitMQConsumer(host, port, user, password, uuid) | ||
# Inside the while loop | ||
sio.start() | ||
logger.warning("Termino ejecucion de server socketio?.. reconectando en 5s") | ||
time.sleep(5) | ||
discover_thread.join() | ||
socketio_thread.join() | ||
rabbit_thread.join() | ||
|
||
|
||
if __name__ == "__main__": | ||
start() | ||
|
||
|
||
try: | ||
start_services() | ||
except Exception as e: | ||
logger.error(f"Error occurred: {e}") | ||
os._exit(1) | ||
|
||
|
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
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