Beispiel #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]
Beispiel #2
0
 def test_instantiate(self, broker_url):
     """Test instantiating worker model"""
     service_name = b"echo"
     verbose = False
     w = MajorDomoWorker(broker_url, service_name, verbose)
     assert w.broker == broker_url
     assert w.service == service_name
     assert w.verbose == verbose
     assert isinstance(w.ctx, zmq.Context)
     assert isinstance(w.poller, zmq.Poller)
Beispiel #3
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"]
Beispiel #4
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
Beispiel #5
0
 def test_send_to_broker_model(self, broker_url):
     """Test send message to broker"""
     b = MajorDomoBroker(False)
     w = MajorDomoWorker(broker_url, b"echo", False)
     w.send_to_broker(constants.W_REQUEST, b.service, [b"test"])
Beispiel #6
0
 def test_reconnect_to_broker_model(self, broker_url):
     """Test reconnecting to broker"""
     b = MajorDomoBroker(False)
     w = MajorDomoWorker(broker_url, b"echo", False)
Beispiel #7
0
 def test_send_to_broker_model(self, broker_url):
     """Test send message to broker"""
     b = MajorDomoBroker(False)
     w = MajorDomoWorker(broker_url, b"echo", False)
     w.send_to_broker(constants.W_REQUEST, b.service, [b"test"])