-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathQueueInterface.php
113 lines (104 loc) · 4.57 KB
/
QueueInterface.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
<?php
namespace TraderInteractive\Mongo;
use MongoDB\BSON\UTCDateTime;
/**
* Abstraction of mongo db collection as priority queue.
*
* Tied priorities are ordered by time. So you may use a single priority for normal queuing (default args exist for
* this purpose). Using a random priority achieves random get()
*/
interface QueueInterface
{
/**
* Ensure an index for the get() method.
*
* @param array $beforeSort Fields in get() call to index before the sort field in same format
* as \MongoDB\Collection::ensureIndex()
* @param array $afterSort Fields in get() call to index after the sort field in same format as
* \MongoDB\Collection::ensureIndex()
*
* @return void
*
* @throws \InvalidArgumentException value of $beforeSort or $afterSort is not 1 or -1 for ascending and descending
* @throws \InvalidArgumentException key in $beforeSort or $afterSort was not a string
*/
public function ensureGetIndex(array $beforeSort = [], array $afterSort = []);
/**
* Ensure an index for the count() method.
* Is a no-op if the generated index is a prefix of an existing one. If you have a similar ensureGetIndex call,
* call it first.
*
* @param array $fields fields in count() call to index in same format as \MongoDB\Collection::createIndex()
* @param bool $includeRunning whether to include the running field in the index
*
* @return void
*
* @throws \InvalidArgumentException key in $fields was not a string
* @throws \InvalidArgumentException value of $fields is not 1 or -1 for ascending and descending
*/
public function ensureCountIndex(array $fields, bool $includeRunning);
/**
* Get a non running message from the queue.
*
* @param array $query in same format as \MongoDB\Collection::find() where top level fields do not contain
* operators. Lower level fields can however. eg: valid {a: {$gt: 1}, "b.c": 3},
* invalid {$and: [{...}, {...}]}
* @param array $options Associative array of get options.
* runningResetDuration => integer
* The duration (in miiliseconds) that the received messages are hidden from
* subsequent retrieve requests after being retrieved by a get() request.
* waitDurationInMillis => integer
* The duration (in milliseconds) for which the call will wait for a message to
* arrive in the queue before returning. If a message is available, the call will
* return sooner than WaitTimeSeconds.
* pollDurationInMillis => integer
* The millisecond duration to wait between polls.
* maxNumberOfMessages => integer
* The maximum number of messages to return with get(). All of the messages are not
* necessarily returned.
*
* @return array Array of messages.
*
* @throws \InvalidArgumentException key in $query was not a string
*/
public function get(array $query, array $options = []) : array;
/**
* Count queue messages.
*
* @param array $query in same format as \MongoDB\Collection::find() where top level fields do not contain
* operators.
* Lower level fields can however. eg: valid {a: {$gt: 1}, "b.c": 3}, invalid {$and: [{...}, {...}]}
* @param bool|null $running query a running message or not or all
*
* @return int the count
*
* @throws \InvalidArgumentException key in $query was not a string
*/
public function count(array $query, bool $running = null) : int;
/**
* Acknowledge a message was processed and remove from queue.
*
* @param Message $message message received from get()
*
* @return void
*/
public function ack(Message $message);
/**
* Atomically acknowledge and send a message to the queue.
*
* @param Message $message message received from get().
*
* @return void
*/
public function requeue(Message $message);
/**
* Send a message to the queue.
*
* @param Message $message The message to enqueue.
*
* @return void
*
* @throws \InvalidArgumentException $priority is NaN
*/
public function send(Message $message);
}