-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Illuminate/Queue integration (#549)
* Adding Illuminate/Queue integration * PHPStan fixes * Psalm fixes * Support illumiate 6.18 * composer normalize * composer fixes * FIxes * cs
- Loading branch information
0 parents
commit fb0179f
Showing
15 changed files
with
524 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/.github export-ignore | ||
/tests export-ignore | ||
/.gitignore export-ignore | ||
/phpunit.xml.dist export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# These are supported funding model platforms | ||
|
||
github: [nyholm, jderusse] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[*.yml] | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: BC Check | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
roave-bc-check: | ||
name: Roave BC Check | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Roave BC Check | ||
uses: docker://nyholm/roave-bc-check-ga |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: Tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
|
||
build: | ||
name: Build | ||
runs-on: ubuntu-latest | ||
strategy: | ||
max-parallel: 10 | ||
matrix: | ||
php: ['7.2', '7.3', '7.4'] | ||
|
||
steps: | ||
- name: Set up PHP | ||
uses: shivammathur/[email protected] | ||
with: | ||
php-version: ${{ matrix.php }} | ||
coverage: xdebug | ||
ini-values: xdebug.overload_var_dump=1 | ||
tools: prestissimo | ||
|
||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Initialize tests | ||
run: make initialize | ||
|
||
- name: Download dependencies | ||
run: | | ||
composer config minimum-stability dev | ||
composer req symfony/phpunit-bridge --no-update | ||
composer update --no-interaction --prefer-dist --optimize-autoloader --prefer-stable | ||
- name: Run tests | ||
run: ./vendor/bin/simple-phpunit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/vendor/ | ||
.php_cs.cache | ||
.phpunit.result.cache | ||
composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Change Log | ||
|
||
## 0.1.0 | ||
|
||
First version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2020 Jérémy Derussé, Tobias Nyholm | ||
|
||
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: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# AsyncAws Illuminate Queue integration | ||
|
||
![](https://github.com/async-aws/illuminate-queue/workflows/Tests/badge.svg?branch=master) | ||
![](https://github.com/async-aws/illuminate-queue/workflows/BC%20Check/badge.svg?branch=master) | ||
|
||
## Install | ||
|
||
```cli | ||
composer require async-aws/illuminate-queue | ||
``` | ||
|
||
## Documentation | ||
|
||
See https://async-aws.com/ for documentation. | ||
|
||
## Contribute | ||
|
||
Contributions are welcome and appreciated. Please read https://async-aws.com/contribute/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"name": "async-aws/illuminate-queue", | ||
"type": "library", | ||
"description": "AsyncAws integration for Illuminate Queue.", | ||
"keywords": [ | ||
"aws", | ||
"async-aws", | ||
"laravel", | ||
"illuminate", | ||
"sqs", | ||
"queue" | ||
], | ||
"license": "MIT", | ||
"require": { | ||
"php": "^7.2.5", | ||
"async-aws/sqs": "^1.0", | ||
"illuminate/queue": "^6.18.11 || ^7.10" | ||
}, | ||
"extra": { | ||
"branch-alias": { | ||
"dev-master": "0.1-dev" | ||
} | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"AsyncAws\\Illuminate\\Queue\\": "src" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"AsyncAws\\Illuminate\\Queue\\Tests\\": "tests/" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.2/phpunit.xsd" | ||
backupGlobals="false" | ||
colors="true" | ||
bootstrap="vendor/autoload.php" | ||
failOnRisky="true" | ||
failOnWarning="true" | ||
> | ||
<php> | ||
<ini name="error_reporting" value="-1" /> | ||
</php> | ||
|
||
<testsuites> | ||
<testsuite name="Test Suite"> | ||
<directory>./tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<filter> | ||
<whitelist> | ||
<directory>./src</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
<?php | ||
|
||
namespace AsyncAws\Illuminate\Queue; | ||
|
||
use AsyncAws\Illuminate\Queue\Job\AsyncAwsSqsJob; | ||
use AsyncAws\Sqs\Enum\QueueAttributeName; | ||
use AsyncAws\Sqs\SqsClient; | ||
use Illuminate\Contracts\Queue\Job; | ||
use Illuminate\Contracts\Queue\Queue as QueueContract; | ||
use Illuminate\Queue\Queue; | ||
use Illuminate\Support\Str; | ||
|
||
/** | ||
* This class is a port from Illuminate\Queue\SqsQueue. | ||
*/ | ||
class AsyncAwsSqsQueue extends Queue implements QueueContract | ||
{ | ||
/** | ||
* The Amazon SQS instance. | ||
* | ||
* @var SqsClient | ||
*/ | ||
protected $sqs; | ||
|
||
/** | ||
* The name of the default queue. | ||
* | ||
* @var string | ||
*/ | ||
protected $default; | ||
|
||
/** | ||
* The queue URL prefix. | ||
* | ||
* @var string | ||
*/ | ||
protected $prefix; | ||
|
||
/** | ||
* The queue name suffix. | ||
* | ||
* @var string | ||
*/ | ||
private $suffix; | ||
|
||
/** | ||
* Create a new Amazon SQS queue instance. | ||
* | ||
* @param string $default | ||
* @param string $prefix | ||
* @param string $suffix | ||
* | ||
* @return void | ||
*/ | ||
public function __construct(SqsClient $sqs, $default, $prefix = '', $suffix = '') | ||
{ | ||
$this->sqs = $sqs; | ||
$this->prefix = $prefix; | ||
$this->default = $default; | ||
$this->suffix = $suffix; | ||
} | ||
|
||
/** | ||
* Get the size of the queue. | ||
* | ||
* @param string|null $queue | ||
* | ||
* @return int | ||
*/ | ||
public function size($queue = null) | ||
{ | ||
$response = $this->sqs->getQueueAttributes([ | ||
'QueueUrl' => $this->getQueue($queue), | ||
'AttributeNames' => [QueueAttributeName::APPROXIMATE_NUMBER_OF_MESSAGES], | ||
]); | ||
|
||
$attributes = $response->getAttributes(); | ||
|
||
return (int) $attributes[QueueAttributeName::APPROXIMATE_NUMBER_OF_MESSAGES]; | ||
} | ||
|
||
/** | ||
* Push a new job onto the queue. | ||
* | ||
* @param \Closure|string|object $job | ||
* @param mixed $data | ||
* @param string|null $queue | ||
* | ||
* @return mixed | ||
*/ | ||
public function push($job, $data = '', $queue = null) | ||
{ | ||
return $this->pushRaw($this->createPayload($job, $queue ?: $this->default, $data), $queue); | ||
} | ||
|
||
/** | ||
* Push a raw payload onto the queue. | ||
* | ||
* @param string $payload | ||
* @param string|null $queue | ||
* | ||
* @return mixed | ||
*/ | ||
public function pushRaw($payload, $queue = null, array $options = []) | ||
{ | ||
return $this->sqs->sendMessage([ | ||
'QueueUrl' => $this->getQueue($queue), 'MessageBody' => $payload, | ||
])->getMessageId(); | ||
} | ||
|
||
/** | ||
* Push a new job onto the queue after a delay. | ||
* | ||
* @param \DateTimeInterface|\DateInterval|int $delay | ||
* @param \Closure|string|object $job | ||
* @param mixed $data | ||
* @param string|null $queue | ||
* | ||
* @return mixed | ||
*/ | ||
public function later($delay, $job, $data = '', $queue = null) | ||
{ | ||
return $this->sqs->sendMessage([ | ||
'QueueUrl' => $this->getQueue($queue), | ||
'MessageBody' => $this->createPayload($job, $queue ?: $this->default, $data), | ||
'DelaySeconds' => $this->secondsUntil($delay), | ||
])->getMessageId(); | ||
} | ||
|
||
/** | ||
* Pop the next job off of the queue. | ||
* | ||
* @param string|null $queue | ||
* | ||
* @return Job|null | ||
*/ | ||
public function pop($queue = null) | ||
{ | ||
$response = $this->sqs->receiveMessage([ | ||
'QueueUrl' => $queue = $this->getQueue($queue), | ||
'AttributeNames' => ['ApproximateReceiveCount'], | ||
]); | ||
|
||
foreach ($response->getMessages() as $message) { | ||
return new AsyncAwsSqsJob( | ||
$this->container, | ||
$this->sqs, | ||
$message, | ||
$this->connectionName, | ||
$queue | ||
); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* Get the queue or return the default. | ||
* | ||
* @param string|null $queue | ||
* | ||
* @return string | ||
*/ | ||
public function getQueue($queue) | ||
{ | ||
$queue = $queue ?: $this->default; | ||
|
||
return false === filter_var($queue, \FILTER_VALIDATE_URL) | ||
? rtrim($this->prefix, '/') . '/' . Str::finish($queue, $this->suffix) | ||
: $queue; | ||
} | ||
|
||
/** | ||
* Get the underlying SQS instance. | ||
* | ||
* @return SqsClient | ||
*/ | ||
public function getSqs() | ||
{ | ||
return $this->sqs; | ||
} | ||
} |
Oops, something went wrong.