EOX GitLab Instance

README.rst 3.29 KB
Newer Older
1
2
3
============================
vsq - View Server Task Queue
============================
Fabian Schindler's avatar
Fabian Schindler committed
4
5


6
* License: MIT license
Fabian Schindler's avatar
Fabian Schindler committed
7
8


9
10
Installation
------------
Fabian Schindler's avatar
Fabian Schindler committed
11

12
Install with pip
Fabian Schindler's avatar
Fabian Schindler committed
13

14
.. code-block:: bash
Fabian Schindler's avatar
Fabian Schindler committed
15

16
   pip install vsq
Fabian Schindler's avatar
Fabian Schindler committed
17
18


19
20
Usage
-----
Fabian Schindler's avatar
Fabian Schindler committed
21

22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
Producer:

.. code-block:: python

   from redis import Redis
   from vsq.queue import Queue

   # create a queue instance
   queue = Queue('queue_name', Redis(...))

   # send a message, which is anything that can be encoded as JSON.
   # a Task object is returned.
   task = queue.put({
      'type': 'myMessageType',
      'payload': ['some', 'values'],
   })

   # some metadata of that task
   print(task.id, task.status, task.created)

   # wait for the task result, ideally with a timeout
   result = task.get(timeout=120)


Consumer:


.. code-block:: python

   from redis import Redis
   from vsq.queue import Queue

   # create a queue instance
   queue = Queue('queue_name', Redis(...))

   # get a single task (with or without timeout):
   task = queue.get_task(timeout=None)

   # a task offers an error capturing context manager API
   with task:
       ...
       task.result = {
           'some': 'result'
       }

   # a queue can be iterated, when listening on an arbitrary amount of messages
   for task in queue:
       with task:
           ...
           task.result = {
               'some': 'result'
           }


Async Queue
...........

``vsq`` provides an async interface mirroring the synchronous one:



.. code-block:: python

   import aioredis
   from vsq.aqueue import Queue

   # create a queue instance
   queue = Queue('queue_name', aioredis.from_url('redis://host:6379'))

   # send a message, which is anything that can be encoded as JSON.
   # a Task object is returned. This is an asynchronous method call
   task = await queue.put({
      'type': 'myMessageType',
      'payload': ['some', 'values'],
   })

   # some metadata of that task
   print(task.id, task.status, task.created)

   # wait for the task result, ideally with a timeout. Also this is
   # asynchronous
   result = await task.get(timeout=120)

   Consumer:


.. code-block:: python

   import aioredis
   from vsq.queue import Queue

   # create a queue instance
   queue = Queue('queue_name', aioredis.from_url('redis://host:6379'))

   # get a single task (with or without timeout):
   task = await queue.get_task(timeout=None)

   # a task offers an error capturing context manager API
   async with task:
       ...
       task.result = {
           'some': 'result
       }

   # a queue can be iterated, when listening on an arbitrary amount of messages
   async for task in queue:
       async with task:
           ...
           task.result = {
               'some': 'result'
           }
Fabian Schindler's avatar
Fabian Schindler committed
133
134
135
136
137


Features
--------

138
139
140
141
142
143
144
145
146
147
148
149
150
``vsq`` provides command line interfaces to easily start a task daemon or to
dispatch messages.


.. code-block:: bash

   # start a task daemon with a given handler function
   python -m vsq.queue daemon myq mymodule.somehandler

   # send a json encoded message
   python -m vsq.queue message myq --json '{"type": "message", "args": "abc"}' --wait


Fabian Schindler's avatar
Fabian Schindler committed
151
152
153
154
155
156
157
158

Credits
-------

This package was created with Cookiecutter_ and the `audreyr/cookiecutter-pypackage`_ project template.

.. _Cookiecutter: https://github.com/audreyr/cookiecutter
.. _`audreyr/cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage