예제 #1
0
파일: service.py 프로젝트: tjrivera/htq
def response(uuid):
    status = htq.status(uuid)

    if not status:
        abort(404)

    # Block until ready
    while True:
        # Poll status until it is complete
        if status not in {htq.QUEUED, htq.PENDING}:
            break

        time.sleep(0.1)
        status = htq.status(uuid)

    rp = htq.response(uuid) or {}

    resp = make_response(json.dumps(rp), 200)
    resp.headers['Content-Type'] = 'application/json'
    resp.headers['Link'] = build_link_header({
        url_for('response', uuid=uuid, _external=True): {
            'rel': 'self',
        },
        url_for('request', uuid=uuid, _external=True): {
            'rel': 'request',
        },
    })

    return resp
예제 #2
0
def response(uuid):
    status = htq.status(uuid)

    if not status:
        abort(404)

    # Block until ready
    while True:
        # Poll status until it is complete
        if status not in {htq.QUEUED, htq.PENDING}:
            break

        time.sleep(0.1)
        status = htq.status(uuid)

    rp = htq.response(uuid) or {}

    resp = make_response(json.dumps(rp), 200)
    resp.headers['Content-Type'] = 'application/json'
    resp.headers['Link'] = build_link_header({
        url_for('response', uuid=uuid, _external=True): {
            'rel': 'self',
        },
        url_for('request', uuid=uuid, _external=True): {
            'rel': 'request',
        },
    })

    return resp
예제 #3
0
파일: test_api.py 프로젝트: tjrivera/htq
    def test_purge(self):
        htq.send(url)
        uuid = htq.pop()

        htq.receive(uuid)
        htq.purge(uuid)

        resp = htq.response(uuid)
        self.assertIsNone(resp)
예제 #4
0
파일: test_api.py 프로젝트: logonmy/htq
    def test_purge(self):
        htq.send(url)
        uuid = htq.pop()

        htq.receive(uuid)
        htq.purge(uuid)

        resp = htq.response(uuid)
        self.assertIsNone(resp)
예제 #5
0
파일: test_api.py 프로젝트: tjrivera/htq
    def test_cancel_complete(self):
        htq.send(url)
        uuid = htq.pop()

        htq.receive(uuid)

        # Cancel will change the state and delete the response
        htq.cancel(uuid)

        req = htq.request(uuid)
        resp = htq.response(uuid)
        self.assertEqual(req['status'], htq.CANCELED)
        self.assertIsNone(resp)
예제 #6
0
파일: test_api.py 프로젝트: logonmy/htq
    def test_cancel_complete(self):
        htq.send(url)
        uuid = htq.pop()

        htq.receive(uuid)

        # Cancel will change the state and delete the response
        htq.cancel(uuid)

        req = htq.request(uuid)
        resp = htq.response(uuid)
        self.assertEqual(req['status'], htq.CANCELED)
        self.assertIsNone(resp)
예제 #7
0
파일: test_api.py 프로젝트: tjrivera/htq
    def test_cancel_queued(self):
        htq.send(url)
        uuid = htq.pop()

        # Cancel while queued
        htq.cancel(uuid)

        # Receive has not effect
        htq.receive(uuid)

        req = htq.request(uuid)
        resp = htq.response(uuid)
        self.assertEqual(req['status'], htq.CANCELED)
        self.assertIsNone(resp)
예제 #8
0
파일: test_api.py 프로젝트: logonmy/htq
    def test_cancel_queued(self):
        htq.send(url)
        uuid = htq.pop()

        # Cancel while queued
        htq.cancel(uuid)

        # Receive has not effect
        htq.receive(uuid)

        req = htq.request(uuid)
        resp = htq.response(uuid)
        self.assertEqual(req['status'], htq.CANCELED)
        self.assertIsNone(resp)
예제 #9
0
파일: test_api.py 프로젝트: tjrivera/htq
    def test_send_receive(self):
        # Send (queue) a request
        htq.send(url)
        self.assertEqual(htq.size(), 1)

        # Pop off UUID for receiving
        uuid = htq.pop()
        self.assertEqual(htq.size(), 0)

        # Actually send request/get response
        htq.receive(uuid)

        # Check states
        req = htq.request(uuid)
        resp = htq.response(uuid)

        self.assertEqual(req['status'], htq.SUCCESS)
        self.assertEqual(resp['code'], 200)
        self.assertEqual(resp['data'], '{"ok": 1}')
        self.assertEqual(resp['headers'], {
            'Content-Type': 'application/json',
        })
예제 #10
0
파일: test_api.py 프로젝트: logonmy/htq
    def test_send_receive(self):
        # Send (queue) a request
        htq.send(url)
        self.assertEqual(htq.size(), 1)

        # Pop off UUID for receiving
        uuid = htq.pop()
        self.assertEqual(htq.size(), 0)

        # Actually send request/get response
        htq.receive(uuid)

        # Check states
        req = htq.request(uuid)
        resp = htq.response(uuid)

        self.assertEqual(req['status'], htq.SUCCESS)
        self.assertEqual(resp['code'], 200)
        self.assertEqual(resp['data'], '{"ok": 1}')
        self.assertEqual(resp['headers'], {
            'Content-Type': 'application/json',
        })