Exemple #1
0
def titanic_request(pipe):
    worker = MajorDomoWorker("tcp://localhost:5555", "titanic.request")

    reply = None

    while True:
        # Send reply if it's not null
        # And then get next request from broker
        request = worker.recv(reply)
        if not request:
            break

        # Ensure message directory exists
        if not os.path.exists(TITANIC_DIR):
            os.mkdir(TITANIC_DIR)

        # Generate UUID and save message to disk
        uuid = uuid4().hex
        filename = request_filename(uuid)
        with open(filename, 'w') as f:
            pickle.dump(request, f)

        # Send UUID through to message queue
        pipe.send(uuid)

        # Now send UUID back to client
        # Done by the worker.recv() at the top of the loop
        reply = ["200", uuid]
Exemple #2
0
def titanic_close():
    worker = MajorDomoWorker("tcp://localhost:5555", "titanic.close")
    reply = None

    while True:
        request = worker.recv(reply)
        if not request:
            break

        uuid = request.pop(0)
        req_filename = request_filename(uuid)
        rep_filename = reply_filename(uuid)

        # should these be protected? Does zfile_delete ignore files
        # that have already been removed? That's what we are doing here
        if os.path.exists(req_filename):
            os.remove(req_filename)
        if os.path.exists(rep_filename):
            os.remove(rep_filename)
        reply = ["200"]
Exemple #3
0
def titanic_reply():
    worker = MajorDomoWorker("tcp://localhost:5555", "titanic.reply")
    reply = None

    while True:
        request = worker.recv(reply)
        if not request:
            break

        uuid = request.pop(0)
        req_filename = request_filename(uuid)
        rep_filename = reply_filename(uuid)
        if os.path.exists(rep_filename):
            with open(rep_filename, 'r') as f:
                reply = pickle.load(f)
            reply = ["200"] + reply
        else:
            if os.path.exists(req_filename):
                reply = ["300"] # pending
            else:
                reply = ["400"] # unknown