def sendMessage(self, command, keyLength, extLength, status, opaque, cas,
        extra=None, body=None):
        bodyLength = 0
        if body:
            bodyLength = len(body) + 4  # flags
        else:
            bodyLength = len(status['message'])
        log.msg('Sending message: %s' % \
            status['message'] if not body else body)

        args = [self.HEADER_STRUCT + '%ds' % bodyLength,
                    self.MAGIC['response'],
                    command,
                    keyLength,
                    extLength,
                    0x00,
                    status['code'],
                    bodyLength,
                    opaque,
                    cas]

        if not body:
            args.append(status['message'])
        else:
            args += ['%s%s' % (struct.pack('!L', extra), body)]

        bin = struct.pack(*args)

        self.transport.write(bin)
Ejemplo n.º 2
0
    def sendMessage(self,
                    command,
                    keyLength,
                    extLength,
                    status,
                    opaque,
                    cas,
                    extra=None,
                    body=None):
        bodyLength = 0
        if body:
            bodyLength = len(body) + 4  # flags
        else:
            bodyLength = len(status['message'])
        log.msg('Sending message: %s' % \
            status['message'] if not body else body)

        args = [
            self.HEADER_STRUCT + '%ds' % bodyLength, self.MAGIC['response'],
            command, keyLength, extLength, 0x00, status['code'], bodyLength,
            opaque, cas
        ]

        if not body:
            args.append(status['message'])
        else:
            args += ['%s%s' % (struct.pack('!L', extra), body)]

        bin = struct.pack(*args)

        self.transport.write(bin)
Ejemplo n.º 3
0
 def marketRisk(self, id):
     node = self.element_objects.get(id, None)
     if node:
         log.msg("Calculating market risk for %s" % node)
         self.refresh()
         return node.mktrisk
     else:
         return None
Ejemplo n.º 4
0
 def marketRisk(self, id):
     node = self.element_objects.get(id,None)
     if node:
         log.msg("Calculating market risk for %s" % node)
         self.refresh()
         return node.mktrisk
     else:
         return None
Ejemplo n.º 5
0
def generate_discount_codes_view():
    try:
        user_id = request.json['user_id']
        number_of_codes = request.json['number_of_codes']
        code_length = request.json['code_length']
    except KeyError as e:
        log.msg(f'Validation Failed: {e}')
        abort(400)
    return {'message': f'Creation of {number_of_codes} codes was initiated'}, 202
    def handleHeader(self, header):
        if len(header) != self.HEADER_SIZE:
            log.msg('Invalid header')
            return False

        (magic, command, keyLength, extLength, dataType, status, bodyLength,
            opaque, cas) = struct.unpack(self.HEADER_STRUCT, header)

        if magic != self.MAGIC['request']:
            log.msg('Invalid magic code 0x%0.2x' % magic)
            return False

        return (magic, command, keyLength, extLength, dataType, status,
            bodyLength, opaque, cas)
Ejemplo n.º 7
0
    def handleHeader(self, header):
        if len(header) != self.HEADER_SIZE:
            log.msg('Invalid header')
            return False

        (magic, command, keyLength, extLength, dataType, status, bodyLength,
         opaque, cas) = struct.unpack(self.HEADER_STRUCT, header)

        if magic != self.MAGIC['request']:
            log.msg('Invalid magic code 0x%0.2x' % magic)
            return False

        return (magic, command, keyLength, extLength, dataType, status,
                bodyLength, opaque, cas)
    def handleCommand(self, magic, command, keyLength, extLength, dataType,
        status, bodyLength, opaque, cas, extra):
        log.msg('Trying to handle command 0x%0.2x' % command)
        commands = dict([(c[1]['command'], c[0]) for c in \
            self.COMMANDS.items()])

        if command not in commands.keys():
            self.sendMessage(command, 0, 0,
                self.STATUSES['unknown_command'], 0, 0)
            return False

        log.msg('Handling %s' % commands[command])

        commandName = 'handle%sCommand' % commands[command].capitalize()
        if hasattr(self, commandName):
            getattr(self, commandName)(magic, command, keyLength, extLength,
            dataType, status, bodyLength, opaque, cas, extra)
            return
Ejemplo n.º 9
0
    def handleCommand(self, magic, command, keyLength, extLength, dataType,
                      status, bodyLength, opaque, cas, extra):
        log.msg('Trying to handle command 0x%0.2x' % command)
        commands = dict([(c[1]['command'], c[0]) for c in \
            self.COMMANDS.items()])

        if command not in commands.keys():
            self.sendMessage(command, 0, 0, self.STATUSES['unknown_command'],
                             0, 0)
            return False

        log.msg('Handling %s' % commands[command])

        commandName = 'handle%sCommand' % commands[command].capitalize()
        if hasattr(self, commandName):
            getattr(self, commandName)(magic, command, keyLength, extLength,
                                       dataType, status, bodyLength, opaque,
                                       cas, extra)
            return
Ejemplo n.º 10
0
def main():
    client = EventBusClient()
    event_consumer = GenerateDiscountCodesEventConsumer(client=client)
    log.msg('Start Consuming events')
    event_consumer.consume()
 def connectionMade(self):
     log.msg('Yay one client!')
Ejemplo n.º 12
0
from flask import Flask, request, abort

from producer import generate_discount_codes_producer
from logger import log

app = Flask(__name__)
log.msg("Server is just started")


@app.route('/generate_discount_codes', methods=['POST'])
def generate_discount_codes_view():
    try:
        user_id = request.json['user_id']
        number_of_codes = request.json['number_of_codes']
        code_length = request.json['code_length']
    except KeyError as e:
        log.msg(f'Validation Failed: {e}')
        abort(400)
    return {'message': f'Creation of {number_of_codes} codes was initiated'}, 202
Ejemplo n.º 13
0
 def connectionMade(self):
     log.msg('Yay one client!')
Ejemplo n.º 14
0
def create_code(user_id: int, code: str):
    log.msg(f'Creating code {code} for user {user_id}')