You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
591 B

import os
import socket
class Sender(object):
def __init__(self, app):
self.app = app
addr, port = os.getenv('CONSUMER_ADDRESS').split(':')
self.address = (addr, int(port))
self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
def __del__(self):
self.socket.close()
def send(self, message):
try:
self.socket.sendto(message, self.address)
except Exception as e:
with self.app.app_context():
self.app.logger.error('Failed to send message: %s', str(e))