コード例 #1
0
ファイル: titanic.py プロジェクト: JuergenNeubauer/mdbase
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]
コード例 #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)
コード例 #3
0
ファイル: titanic.py プロジェクト: JuergenNeubauer/mdbase
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"]
コード例 #4
0
ファイル: titanic.py プロジェクト: JuergenNeubauer/mdbase
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
コード例 #5
0
ファイル: test_worker.py プロジェクト: JuergenNeubauer/mdbase
 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"])
コード例 #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)
コード例 #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"])