Commit 1364cee8 authored by xa's avatar xa

Merge branch 'docs' into 'master'

Docs



See merge request !10
parents 2f7bc2ac 3575969b
Pipeline #657 passed with stages
......@@ -3,16 +3,19 @@
stages:
- build
- test
- documentation
- release
Prepare container:
prepare container:
stage: build
script:
- docker build -t errorist/aiodisque:latest .
tags:
- docker-build
except:
- docs
Test:
test:
stage: test
image: errorist/aiodisque:latest
script:
......@@ -21,8 +24,10 @@ Test:
- py.test tests/ --cov aiodisque --cov-report term-missing --flake8
tags:
- python3.5
except:
- docs
Release to pypi:
release to pypi:
stage: release
image: errorist/aiodisque:latest
script:
......@@ -34,7 +39,7 @@ Release to pypi:
- /^v[\d\.]+.*$/
allow_failure: true
Upload documentation:
notify RTFD:
stage: release
image: errorist/aiodisque:latest
script:
......@@ -44,3 +49,18 @@ Upload documentation:
only:
- master
allow_failure: true
pages:
stage: documentation
script:
- python -m pip install sphinx
- python -m pip install -r docs/requirements.txt
- sphinx-build -b html docs public
artifacts:
paths:
- public
only:
- master
- docs
tags:
- python3.5
......@@ -68,5 +68,18 @@ In addition to the changes above, it implements some async sugar:
# ... connection has been lost here...
await client.hello() # this not fails
For more details about the python implementation, you can consult the
`AIO Disque documentation`_.
TODO
----
* use state object instead of str for pause.
* more tests for qstat.
* handle -PAUSED errors and None queues (qstat).
* document pur python/asyncio feature.
.. _Disque: https://github.com/antirez/disque
.. _`official Disque command documentation`: https://github.com/antirez/disque#main-api
.. _`AIO Disque documentation`: http://aio.pages.errorist.xyz/aiodisque
......@@ -342,7 +342,7 @@ class Disque:
listed above. They may be (unlikely) removed or more can be (likely)
added in the future.
If a queue does not exist, NULL is returned. Note that queues are
If a queue does not exist, None is returned. Note that queues are
automatically evicted after some time if empty and without clients
blocked waiting for jobs, even if there are active jobs for the queue.
......@@ -544,13 +544,17 @@ class Disque:
possibly broadcasting the command to other nodes in the cluster.
Disque queues can be paused in both directions, input and output or
both. Pausing a queue makes it not available for input or output
operations
operations.
The command always returns the state of the queue after the execution
of the specified options, so the return value is one of `in`, `out`,
`all` or `none`.
Parameters:
queue (str): the queue name
*options: list of options
Returns:
str
str: one of "in", "out", "all" or "none" value
"""
assert options, 'at least one option required'
response = await self.execute_command('PAUSE', queue, *options)
......
......@@ -42,4 +42,4 @@ def encode_command(*args):
continue
raise TypeError("Argument {!r} expected to be of bytes,"
" str, int or float type".format(arg))
return buf
return bytes(buf)
......@@ -28,6 +28,31 @@ Some changes must be noticed:
* commands are coroutines and thay names are lowered.
* ``async`` is a reserved word in Python, everyfields are renamed asynchronous
Natural Python
--------------
This library tries to make a natural bridge between Python idioms like
iterators, queues and disque_:
* Fancy async iterators::
async for jobs in client.client.getjob_iter('q', nohang=True):
print(jobs)
async for queue in client.qscan_iter(count=128):
print(queue)
async for job in client.jscan_iter(count=128):
print(job)
* There is also an experimentaton that try to mimic an asyncio.Queue::
from aiodisque.queue import Queue
queue = JobsQueue('queue', client)
job_id = await queue.put('job')
job = await queue.get()
assert job.id == job_id
Other goodies
-------------
......
47085f92d651661eab5409c84772c786e82acaaa :0 myself 0 0 connected
......@@ -50,6 +50,7 @@ async def test_job(node, event_loop):
client = Disque(node.port, loop=event_loop)
job_id = await client.addjob('foo', 'bar')
assert job_id.startswith('D-')
assert len(job_id) == 40
job = await client.getjob('foo')
assert isinstance(job, Job)
......
import pytest
from aiodisque.util import encode_command
def test_encode_command():
data = encode_command('foo')
assert data == b'*1\r\n$3\r\nfoo\r\n'
data = encode_command(42)
assert data == b'*1\r\n$2\r\n42\r\n'
with pytest.raises(TypeError):
encode_command(None)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment