Skip to content

Commit b593e6c

Browse files
committed
v2.0.6 Backport release
1 parent 8604cbd commit b593e6c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+2110
-1546
lines changed

LICENSE

+5-18
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,8 @@
1-
The MIT License (MIT)
1+
Copyright 2013-2019 Sergei Shilko
2+
Copyright 2016-2019 Carolina Alarcon
23

3-
Copyright (c) 2016 Sergei Shilko
4+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
45

5-
Permission is hereby granted, free of charge, to any person obtaining a copy
6-
of this software and associated documentation files (the "Software"), to deal
7-
in the Software without restriction, including without limitation the rights
8-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9-
copies of the Software, and to permit persons to whom the Software is
10-
furnished to do so, subject to the following conditions:
6+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
117

12-
The above copyright notice and this permission notice shall be included in all
13-
copies or substantial portions of the Software.
14-
15-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
8+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

+41-171
Original file line numberDiff line numberDiff line change
@@ -1,197 +1,67 @@
11
backq
22
=====
33

4-
Perform tasks with workers & publishers (queues)
4+
Background tasks with workers & publishers via queues
55

6-
* [APNS](https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW9) Push notifications sending
7-
* asynchronous process executon via [proc_open](http://php.net/manual/en/function.proc-open.php) implemented by [symfony/process](http://symfony.com/doc/current/components/process.html) component
6+
* Sending [APNS](https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW9) push notifications (Legacy API)
7+
* Sending [FCM](https://firebase.google.com/docs/cloud-messaging) push notifications to Android (GCM/FCM)
8+
* Sending [AWS SNS](https://aws.amazon.com/sns/) push notifications via AWS SNS arn's
9+
* Executing [Psr7\Request](https://www.php-fig.org/psr/psr-7/) asynchronously via Guzzle
10+
* Executing **any** processes with [symfony/process](http://symfony.com/doc/current/components/process.html)
11+
* [Long delay scheduling](https://aws.amazon.com/blogs/aws/new-manage-dynamodb-items-using-time-to-live-ttl/) via DynamoSQS Adapter and Serialized worker, for reliable long-term scheduled jobs
12+
* Extendable - write your own worker and use existing adapters out of the box ...
813

914
#### Installation
1015
```
11-
#composer self-update
12-
#composer clear-cache
13-
#composer diagnose
14-
composer require sshilko/backq:^1.9
16+
#composer self-update && composer clear-cache && composer diagnose
17+
composer require sshilko/backq:^2.0
1518
```
1619

17-
#### Requirements
20+
#### Supported queue servers
1821

19-
* Recommended [PHP >=7.0.4](https://launchpad.net/~ondrej/+archive/ubuntu/php)
20-
* Required PHP 5.5 ([generators](http://php.net/manual/en/language.generators.overview.php) & coroutines)
21-
* Simple & Fast work queue [Beanstalkd](https://github.com/kr/beanstalkd/blob/master/doc/protocol.txt) davidpersson/beanstalk [library](https://github.com/davidpersson/beanstalk)
22+
* [Beanstalkd](https://github.com/kr/beanstalkd/blob/master/doc/protocol.txt)
23+
* [Redis](https://redis.io)
24+
* [NSQ](https://nsq.io)
25+
* [DynamoDB](https://aws.amazon.com/dynamodb/) [SQS](https://aws.amazon.com/sqs/) [Lambda](https://aws.amazon.com/lambda/) for DynamoSQS adapter
2226

23-
#### Push notifications requirements
27+
#### Features
2428

25-
* Basic idea inspired by [ApnsPHP](https://packagist.org/packages/duccio/apns-php) [original](https://code.google.com/archive/p/apns-php/) but because package was not maintained for long time, own adapter was implemented (TLS support, payload size >= 256 in iOS8+, fwrite()/fread() error handlind, etc.).
29+
Workers compatibility with adapters
2630

27-
#### Process dispatch requirements
28-
29-
* Processes are spawned via [symfony/process](http://symfony.com/doc/current/components/process.html) component
30-
31-
#### Licence
32-
[MIT](http://opensource.org/licenses/MIT)
31+
| Adapter / Worker |[FCM](https://firebase.google.com/docs/cloud-messaging)|[APNS](https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW9)|[Process](http://symfony.com/doc/current/components/process.html)|[Guzzle](https://www.php-fig.org/psr/psr-7/)|Serialized|
32+
|----|---|---|---|---|---|
33+
| [Beanstalkd](https://beanstalkd.github.io/) | + | + | + | + | + |
34+
| [Redis](https://redis.io) | + | + | + | + | ? |
35+
| [NSQ](https://nsq.io/) | + | + | + | + | ? |
36+
| [DynamoSQS](https://aws.amazon.com/) | + | + | + | + | + |
3337

34-
#### Review
38+
Adapter implemented features
3539

36-
[Blog post about sending Apple push notifications](http://moar.sshilko.com/2014/09/09/APNS-Workers/)
40+
| Adapter / Feature | ping | hasWorkers | setWorkTimeout |
41+
|---|---|---|---|
42+
| [Beanstalkd](https://beanstalkd.github.io/) | + | + | +
43+
| [Redis](https://redis.io) | + | - | +
44+
| [NSQ](https://nsq.io/) | + | - | *
45+
| [DynamoSQS](https://aws.amazon.com/) | - | - | +
3746

38-
#### API / Basic Usage / APNS push notifications
47+
Worker available features
3948

40-
Initialize Queue adapter
49+
- `setRestartThreshold` (limit max number of jobs cycles, then terminate)
50+
- `setIdleTimeout` (limit max idle time, then terminating)
4151

42-
* Adapter for Beanstalkd
43-
```
44-
/**
45-
* only Beanstalk is supported atm.
46-
* Recommended: default settings expect server at 127.0.0.1:11300 with non-persistent connection
47-
*/
48-
$adapter = new \BackQ\Adapter\Beanstalk;
49-
//$custom = new \BackQ\Adapter\Beanstalk($host, $port, $timeout, $persistent);
50-
```
52+
TLDR
5153

52-
* Worker (can have multiple per same queue) that dispatches messages
54+
![Backq](https://github.com/sshilko/backq/raw/master/example/example.jpg "Background tasks with workers and publishers via queues")
5355

54-
```
55-
$ca = 'somepath/entrust_2048_ca.cer';
56-
$pem = 'somepath/apnscertificate.pem';
57-
$env = \ApnsPHP_Abstract::ENVIRONMENT_SANDBOX;
58-
59-
$worker = new \BackQ\Worker\Apnsd($adapter);
60-
61-
/**
62-
* We can listen to custom queue and have multiple queues & multiple workers per queue
63-
* @optional
64-
*/
65-
$worker->setQueueName($worker->getQueueName() . 'myQueueName1');
66-
67-
/**
68-
* The longer we wait
69-
* the less chance that we will send push into closed socket (eof)
70-
* @optional
71-
*/
72-
$worker->socketSelectTimeout = \BackQ\Worker\Apnsd::SENDSPEED_TIMEOUT_RECOMMENDED;
73-
74-
$worker->setLogger(new \BackQ\Logger('somepath/logfile.txt'));
75-
76-
$worker->setRootCertificationAuthority($ca);
77-
$worker->setCertificate($pem);
78-
$worker->setEnvironment($env);
79-
80-
/**
81-
* Output basic debug
82-
*/
83-
//$worker->toggleDebug(true);
84-
85-
/**
86-
* Quit the worker after processing 1000 pushes
87-
* @optional
88-
*/
89-
$worker->setRestartThreshold(1000);
90-
91-
/**
92-
* Quit the worker if no jobs received for 600 seconds
93-
* @optional
94-
*/
95-
$worker->setIdleTimeout(600);
96-
97-
/**
98-
* Set stream_set_timeout() for stream_socket_client()
99-
* @optional
100-
*/
101-
$worker->readWriteTimeout = 5;
102-
103-
/**
104-
* Workaround for
105-
* PHP 5.5.23,5.5.24 & 5.6.7,5.6.8
106-
* does not honor the stream_set_timeout()
107-
* @see https://bugs.php.net/bug.php?id=69393
108-
*/
109-
//$worker->connectTimeout = 2;
110-
111-
$worker->run();
112-
```
113-
114-
* Publisher pushes new messages into Beanstalkd queue
56+
See [/example](https://github.com/sshilko/backq/tree/master/example) folder for usage examples
11557

116-
```
117-
$publisher = \BackQ\Publisher\Apnsd::getInstance(new \BackQ\Adapter\Beanstalk);
118-
119-
/**
120-
* We can publish to custom queue
121-
* @optional
122-
*/
123-
$publisher->setQueueName($worker->getQueueName() . 'myQueueName1');
124-
125-
/**
126-
* Give 4 seconds to dispatch the message (time to run)
127-
* Unless worker reports successfuly that job is done, the job is put back into "ready" state
128-
* @optional
129-
*/
130-
$params = array(\BackQ\Adapter\Beanstalk::PARAM_JOBTTR => 4);
131-
132-
/**
133-
* Delay sending push by 10 seconds
134-
* @optional
135-
*/
136-
$params[\BackQ\Adapter\Beanstalk::PARAM_READYWAIT] = 10;
137-
138-
/**
139-
* Ensure adapter can connect to Beanstalk & has workers WAITING for the job
140-
*/
141-
if ($publisher->start() && $publisher->hasWorkers()) {
142-
/**
143-
* Original ApnsPHP messages supported, recommended customized \BackQ\Message\ApnsPHP
144-
*/
145-
$messages = array();
146-
for ($i=0; $i < count($messages); $i++) {
147-
$result = $publisher->publish($messages[$i], $params);
148-
if ($result > 0) {
149-
/**
150-
* successfully added to dispatch queue
151-
*/
152-
} else {
153-
/**
154-
* Fallback here
155-
*/
156-
}
157-
}
158-
} else {
159-
/**
160-
* Fallback here
161-
*
162-
* + Unable to connect to Beanstalk
163-
* + No workers currently waiting for job (all of them busy processing or none launched)
164-
*/
165-
}
166-
```
58+
#### Old version 1 detailed review
16759

168-
#### Basic usage (processes)
169-
170-
A queue for the [symfony/process](http://symfony.com/doc/current/components/process.html) component usage.
171-
A simple scheduler is done using Beanstalkd `delay` option for jobs. Or just dispatch projess jobs for async execution.
172-
173-
Worker daemon
174-
```
175-
$worker = new \BackQ\Worker\AProcess(new \BackQ\Adapter\Beanstalk);
176-
$worker->run();
177-
```
60+
[Blog post about sending Apple push notifications](http://moar.sshilko.com/2014/09/09/APNS-Workers/)
17861

179-
Publisher
180-
```
181-
$publisher = \BackQ\Publisher\Process::getInstance(new \BackQ\Adapter\Beanstalk);
182-
if ($publisher->start() && $publisher->hasWorkers()) {
183-
$message = new \BackQ\Message\Process('echo $( date +%s ) >> /tmp/test');
184-
$result = $publisher->publish($message, array(\BackQ\Adapter\Beanstalk::PARAM_JOBTTR => 3,
185-
\BackQ\Adapter\Beanstalk::PARAM_READYWAIT => 4));
186-
if ($result > 0) {
187-
//Async process job added to queue
188-
} else {
189-
//fail
190-
}
191-
}
192-
```
62+
#### Licence
63+
MIT
19364

194-
#### Master-dev
65+
Copyright 2013-2019 Sergei Shilko
19566

196-
Please use only stable (>=1.1.2) versions, everyone <= 1.1.2 should update for latest bugfixes around sockets io.
19767

UPGRADING

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
-------------------------------------------------------------------------------
2+
2.0.6
3+
4+
1. Backward Incompatible Changes
5+
2. New Features
6+
3. Deprecated Functionality
7+
4. Performance Improvements
8+
9+
========================================
10+
1. Backward Incompatible Changes
11+
========================================
12+
13+
- Publisher:
14+
- All the `Publisher`'s are now `abstract` classes
15+
- `__construct` no longer accepts adapter, define `setupAdapter` instead
16+
- `setupAdapter` is new method that set-up's the adapter instead of constructor
17+
- `__wakeup` and `__sleep` are now defined on `AbstractPublisher` for serialization
18+
19+
========================================
20+
2. New Features
21+
========================================
22+
23+
Will now keep track of changes in UPGRADING document.
24+
25+
New `Serialized` idea is a worker/queue/publisher that wrap messages from other publishers, currently
26+
this is used to reliably delay long tasts (i.e. something to be scheduled in two weeks), and is used together
27+
with new `DynamoSQS` adapter that saves jobs to AWS DynamoDB and once jobs are ready (TTL triggers) they end up
28+
in SQS queue (DynamoDB->DynamoDB Stream->Lambda->SQS) where they are picked up by worker.
29+
`DynamoSQS` uses DynamoDB for saving and SQS for picking jobs.
30+
31+
- Publisher:
32+
- New `Serialized` publisher
33+
- Workers:
34+
- New `Serialized` worker
35+
- New `Closure` worker
36+
- Message
37+
- New `Serialized` message
38+
- Adapter
39+
- New `DynamoSQS` adapter
40+
41+
========================================
42+
3. Deprecated Functionality
43+
========================================
44+
45+
`Nsq` adapter is no longer maintaned as it's performance is too low. The benefit it has is built-in dashboard
46+
and status of queues. You can continue using it as is.
47+
48+
`toggleDebug()` is removed on workers, they now use standard PSR logger, by default with NORMAL verbose level and
49+
output to console
50+
51+
`debug()` is removed on workers, replaced with `logDebug()`
52+
53+
========================================
54+
4. Performance Improvements
55+
========================================
56+
57+
Refactored internal worker generator loop for handling of empty loops, this affects the APNS worker directly
58+
and possibly others.
59+
Recommended PHP version 7.2 or 7.3.
60+
61+
-------------------------------------------------------------------------------
62+
1.9.13
63+
64+
1. New Features
65+
2. Deprecated Functionality
66+
3. Performance Improvements
67+
68+
========================================
69+
1. New Features
70+
========================================
71+
Summarizing all changes between 1.3 and 1.9.
72+
1.9.13 is last stable and recommended release in version 1.
73+
74+
- Adapter
75+
- New `NSQ` adapter for nsq.io server (distributed, scalable, has built-in ui)
76+
- New `Redis` adapter based on illuminate/redis and illuminate/queue
77+
78+
========================================
79+
2. Deprecated Functionality
80+
========================================
81+
82+
`GCM` worker, adapter and message are removed in favor of `Fcm`.
83+
84+
========================================
85+
3. Performance Improvements
86+
========================================
87+
88+
Many bugfixes and improvements, please use latest 1.9 release.
89+
New logger api.
90+
91+
92+

composer.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "sshilko/backq",
33
"license": "MIT",
4-
"description": "Background push notifications processing with workers & publisher",
4+
"description": "Background jobs processing with queue, workers & publishers",
55
"type": "library",
66
"minimum-stability": "dev",
77
"support": {
88
"issues": "https://github.com/sshilko/backq/issues"
99
},
10-
"keywords": ["queue", "worker", "apns", "push", "ios", "apple", "notification", "send", "background", "process", "async"],
10+
"keywords": ["queue", "worker", "apns", "push", "ios", "fcm", "apple", "guzzle", "process", "notification", "sqs", "dynamodb", "send", "background", "async"],
1111
"homepage": "https://github.com/sshilko/backq",
1212
"require": {
1313
"php": "^7.1",
@@ -16,7 +16,8 @@
1616
"symfony/process": "^4.2",
1717
"duccio/apns-php": "=1.0.1",
1818
"illuminate/queue": "^5.8",
19-
"illuminate/redis": "^5.8"
19+
"illuminate/redis": "^5.8",
20+
"aws/aws-sdk-php": "^3.11"
2021
},
2122
"autoload": {
2223
"psr-4": { "BackQ\\": "src/" }

0 commit comments

Comments
 (0)