Skip to content

Commit

Permalink
Update python-socketio version in requirements files
Browse files Browse the repository at this point in the history
Update tag and release name for v1.0.7
Update tag and release name for v1.0.6
Update tag and release name for v1.0.5
Refactor EscPComandos.py to use the 'total' variable for printing the total amount
Update tag and release name for v1.0.8
Update release name for v1.0.8
Update requirements.cli.txt and requirements.kivy.txt to include 'pika'
Update requirements.txt to include 'pika'
Refactor ComandosHandler.py to handle different data types for commands
Update Configberry.py to print the config file path
Add RabbitMQConsumer.py to handle consuming messages from RabbitMQ
  • Loading branch information
alevilar committed Sep 20, 2024
1 parent 03ec2f5 commit 6eec9d9
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/desktop.build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v1.0.7
release_name: Release v1.0.7
tag_name: v1.0.8
release_name: Release v1.0.8
draft: false
prerelease: false

Expand Down
1 change: 1 addition & 0 deletions requirements.cli.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ argparse==1.4.0
uuid==1.30
appdirs==1.4.4
platformdirs==4.2.2
pika
1 change: 1 addition & 0 deletions requirements.kivy.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ uuid==1.30
appdirs==1.4.4
platformdirs==4.2.2
kivy==2.3.0
pika
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ kivy==2.3.0
cython==3.0.11
buildozer==1.5.0
pyjnius==1.6.1
twisted==24.7.0
twisted==24.7.0
pika
18 changes: 12 additions & 6 deletions src/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,31 @@


# importo el modulo que se encarga de la comunicacion con el servidor
from common.fiscalberry_sio import FiscalberrySio
from common.rabbit_mq_consumer import RabbitMQConsumer
from common.discover import send_discover_in_thread
import asyncio



def start():
logger.info("Iniciando Fiscalberry Server")

serverUrl = configberry.config.get("SERVIDOR", "sio_host", fallback="")
uuid = configberry.config.get("SERVIDOR", "uuid")
send_discover_in_thread()
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()

while True:

sio = FiscalberrySio(serverUrl, uuid)
sio.start_print_server()
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)


if __name__ == "__main__":
start()
start()

19 changes: 13 additions & 6 deletions src/common/ComandosHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,22 @@ class ComandosHandler:

def send_command(self, comando):
response = {}
logger.info(f"Request \n -> {comando}")
logger.info(f"Tipo de dato de comando: {type(comando)}")
try:
if isinstance(comando, str):
logger.info("es un string??")
jsonMes = json.loads(comando, strict=False)
else:
#si es un diccionario o json, no hacer nada
elif isinstance(comando, dict):
logger.info("es un diccionario??")
jsonMes = comando
#si es del typo class bytes, convertir a string y luego a json
elif isinstance(comando, bytes):
logger.info("es un bytes??")
jsonMes = json.loads(comando.decode("utf-8"), strict=False)
else:
raise TypeError("Tipo de dato no soportado")

response = self.__json_to_comando(jsonMes)
except TypeError as e:
errtxt = "Error parseando el JSON %s" % e
Expand All @@ -159,7 +169,7 @@ def send_command(self, comando):
logger.exception(errtxt)
response["err"] = errtxt
except Exception as e:
errtxt = repr(e) + "- " + str(e)
errtxt = "Error desconocido: " + repr(e) + "- " + str(e)
logger.exception(errtxt)
response["err"] = errtxt

Expand All @@ -173,7 +183,6 @@ def __json_to_comando(self, jsonTicket):
traductor = None

rta = {"rta": ""}

try:

# seleccionar impresora
Expand Down Expand Up @@ -215,9 +224,7 @@ def __json_to_comando(self, jsonTicket):
elif 'removerImpresora' in jsonTicket:
rta["rta"] = self._removerImpresora(
jsonTicket["removerImpresora"])

else:
logging.error("No se pasó un comando válido")
raise TraductorException("No se pasó un comando válido")

# cerrar el driver
Expand Down
2 changes: 1 addition & 1 deletion src/common/Configberry.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def getConfigFIle(self):

CONFIG_FILE_NAME = os.path.join(configDirPath, 'config.ini')

self.logger.debug("Config file path: %s" % CONFIG_FILE_NAME)
print("Config file path: %s" % CONFIG_FILE_NAME)

return CONFIG_FILE_NAME

Expand Down
56 changes: 56 additions & 0 deletions src/common/rabbit_mq_consumer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env python

import threading, os, pika

from common.ComandosHandler import ComandosHandler, TraductorException
from common.fiscalberry_logger import getLogger


class RabbitMQConsumer:

STREAM_NAME = "paxaprinter"

# 5GB
STREAM_RETENTION = 5000000000

def __init__(self, host, port, user, password, uuid):
self.host = host
self.port = port
self.user = user
self.password = password
self.connection = None
self.channel = None

self.client_uuid = uuid

# Configuro logger según ambiente
environment = os.getenv('ENVIRONMENT', 'production')
if environment == 'development':
sioLogger = True
else:
sioLogger = False

self.logger = getLogger()



def start(self):

connection = pika.BlockingConnection(pika.ConnectionParameters(host=self.host, port=self.port, credentials=pika.PlainCredentials(self.user, self.password)))
channel = connection.channel()

#channel.exchange_declare(exchange=self.STREAM_NAME, exchange_type='direct')
queue_name = self.client_uuid
channel.queue_declare(queue=queue_name)
channel.queue_bind(exchange=self.STREAM_NAME, queue=queue_name, routing_key=self.client_uuid)

def callback(ch, method, properties, body):
comandoHandler = ComandosHandler()
comandoHandler.send_command(body)

channel.basic_consume(queue=queue_name, on_message_callback=callback, auto_ack=True)
print(f"Waiting for messages in queue: {queue_name}")
channel.start_consuming()



0 comments on commit 6eec9d9

Please sign in to comment.