3
3
[ ![ Build Status] ( https://travis-ci.org/tarantool-php/queue.svg?branch=master )] ( https://travis-ci.org/tarantool-php/queue )
4
4
[ ![ Scrutinizer Code Quality] ( https://scrutinizer-ci.com/g/tarantool-php/queue/badges/quality-score.png?b=master )] ( https://scrutinizer-ci.com/g/tarantool-php/queue/?branch=master )
5
5
[ ![ Code Coverage] ( https://scrutinizer-ci.com/g/tarantool-php/queue/badges/coverage.png?b=master )] ( https://scrutinizer-ci.com/g/tarantool-php/queue/?branch=master )
6
+ [ ![ Mentioned in Awesome PHP] ( https://awesome.re/mentioned-badge.svg )] ( https://github.com/ziadoz/awesome-php )
6
7
7
8
[ Tarantool] ( http://tarantool.org/ ) is a NoSQL database running in a Lua application server. It integrates
8
9
Lua modules, called [ LuaRocks] ( https://luarocks.org/ ) . This package provides PHP bindings for
9
10
[ Tarantool Queue LuaRock] ( https://github.com/tarantool/queue/ ) .
10
11
11
12
13
+ ## Table of contents
14
+
15
+ * [ Installation] ( #installation )
16
+ * [ Before start] ( #before-start )
17
+ * [ Working with queue] ( #working-with-queue )
18
+ * [ Data types] ( #data-types )
19
+ * [ Tasks] ( #tasks )
20
+ * [ Producer API] ( #producer-api )
21
+ * [ Consumer API] ( #consumer-api )
22
+ * [ Statistics] ( #statistics )
23
+ * [ Custom methods] ( #custom-methods )
24
+ * [ Tests] ( #tests )
25
+ * [ License] ( #license )
26
+
27
+
12
28
## Installation
13
29
14
30
The recommended way to install the library is through [ Composer] ( http://getcomposer.org ) :
15
31
16
- ``` sh
17
- $ composer require tarantool/queue
32
+ ``` bash
33
+ composer require tarantool/queue
18
34
```
19
35
20
36
@@ -38,8 +54,8 @@ queue.create_tube('foobar', 'fifottl', {if_not_exists=true})
38
54
To start the instance you need to copy (or symlink) ` queues.lua ` file into the ` /etc/tarantool/instances.enabled `
39
55
directory and run the following command:
40
56
41
- ``` sh
42
- $ sudo tarantoolctl start queues
57
+ ``` bash
58
+ sudo tarantoolctl start queues
43
59
```
44
60
45
61
@@ -104,15 +120,15 @@ Task::isDelayed()
104
120
105
121
As you've already seen, to insert a task into a queue you need to call ` put() ` method, which accepts
106
122
two arguments: the data you want to process and optional array of task options, which this particular
107
- queue supports. For example, ` fifottl ` queue (which we defined earlier in our Lua config file),
108
- supports ` delay ` , ` ttl ` , ` ttr ` and ` pri ` options:
123
+ queue supports. For example, ` fifottl ` queue (which we defined [ earlier] ( #before-start ) in our Lua config
124
+ file), supports ` delay ` , ` ttl ` , ` ttr ` and ` pri ` options:
109
125
110
126
``` php
111
127
use Tarantool\Queue\Options;
112
128
113
- $queue->put('foo', [Options::DELAY => 30]);
114
- $queue->put('bar', [Options::TTL => 5]);
115
- $queue->put('baz', [Options::TTR => 10, Options::PRI => 42]);
129
+ $queue->put('foo', [Options::DELAY => 30.0 ]);
130
+ $queue->put('bar', [Options::TTL => 5.0 ]);
131
+ $queue->put('baz', [Options::TTR => 10.0 , Options::PRI => 42]);
116
132
```
117
133
118
134
> * See the full list of available options [ here] ( https://github.com/tarantool/queue#queue-types ) .*
@@ -128,7 +144,7 @@ The method returns either a [Task](#tasks) object or `null`:
128
144
$taskOrNull = $queue->take();
129
145
130
146
// wait 2 seconds
131
- $taskOrNull = $queue->take(2);
147
+ $taskOrNull = $queue->take(2.0 );
132
148
133
149
// wait 100 milliseconds
134
150
$taskOrNull = $queue->take(.1);
@@ -150,7 +166,7 @@ Or put back into the queue in case it cannot be executed:
150
166
$task = $queue->release($task->getId());
151
167
152
168
// for *ttl queues you can specify a delay
153
- $task = $queue->release($task->getId(), [Options::DELAY => 30]);
169
+ $task = $queue->release($task->getId(), [Options::DELAY => 30.0 ]);
154
170
```
155
171
156
172
To look at a task without changing its state, use:
@@ -174,7 +190,7 @@ $count = $queue->kick(3); // kick 3 buried tasks
174
190
To increase TTR and/or TTL of a running task (only for * ttl queues):
175
191
176
192
``` php
177
- $taskOrNull = $queue->touch($takenTask->getId(), 5); // increase ttr/ttl to 5 seconds
193
+ $taskOrNull = $queue->touch($takenTask->getId(), 5.0 ); // increase ttr/ttl to 5 seconds
178
194
```
179
195
180
196
A task (in any state) can be deleted permanently with ` delete() ` :
@@ -259,41 +275,41 @@ end
259
275
To call this method on a ` $queue ` object, use ` Queue::call() ` :
260
276
261
277
``` php
262
- $result = $queue->call('put_many', [[
263
- 'foo' => ['foo', [Options::DELAY => 30]],
278
+ $result = $queue->call('put_many', [
279
+ 'foo' => ['foo', [Options::DELAY => 30.0 ]],
264
280
'bar' => ['bar'],
265
- ]] );
281
+ ]);
266
282
```
267
283
268
284
269
285
## Tests
270
286
271
287
The easiest way to run tests is with Docker. First, build an image using the [ dockerfile.sh] ( dockerfile.sh ) generator:
272
288
273
- ``` sh
274
- $ ./dockerfile.sh | docker build -t queue -
289
+ ``` bash
290
+ ./dockerfile.sh | docker build -t queue -
275
291
```
276
292
277
293
Then run Tarantool instance (needed for integration tests):
278
294
279
- ``` sh
280
- $ docker network create tarantool-php
281
- $ docker run -d --net=tarantool-php --name=tarantool -v ` pwd` :/queue \
295
+ ``` bash
296
+ docker network create tarantool-php
297
+ docker run -d --net=tarantool-php --name=tarantool -v ` pwd` :/queue \
282
298
tarantool/tarantool:1 tarantool /queue/tests/Integration/queues.lua
283
299
```
284
300
285
301
And then run both unit and integration tests:
286
302
287
- ``` sh
288
- $ docker run --rm --net=tarantool-php --name=queue -v ` pwd` :/queue -w /queue queue
303
+ ``` bash
304
+ docker run --rm --net=tarantool-php --name=queue -v ` pwd` :/queue -w /queue queue
289
305
```
290
306
291
307
To run only integration or unit tests, set the ` PHPUNIT_OPTS ` environment variable
292
- to either ` --testsuite Integration ` or ` --testsuite Unit ` respectively, e.g.:
308
+ to either ` --testsuite integration ` or ` --testsuite unit ` respectively, e.g.:
293
309
294
- ``` sh
295
- $ docker run --rm --net=tarantool-php --name=queue -v ` pwd` :/queue -w /queue \
296
- -e PHPUNIT_OPTS=' --testsuite Unit ' queue
310
+ ``` bash
311
+ docker run --rm --net=tarantool-php --name=queue -v ` pwd` :/queue -w /queue \
312
+ -e PHPUNIT_OPTS=' --testsuite unit ' queue
297
313
```
298
314
299
315
0 commit comments