Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: test

on:
pull_request:

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout to GitHub workspace
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Test
continue-on-error: false
env:
CI_PULL_REQUEST_TITLE: ${{ github.event.pull_request.title }}
run: |
# Commitlint
npx --version
npm install --location=global --save-dev @commitlint/config-conventional
echo "module.exports = {
extends: ['@commitlint/config-conventional'],
rules: {
'header-max-length': [2, 'always', 100]
}
}" >commitlint.config.js
npx commitlint --to HEAD --verbose
echo "$CI_PULL_REQUEST_TITLE" | npx commitlint

# Functional Tests
composer install --prefer-dist
./vendor/bin/phpunit
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/vendor
.phpunit.result.cache
.phpunit.*cache
composer.lock
104 changes: 52 additions & 52 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,57 +1,57 @@
{
"name": "culturalinfusion/laravel-sqs-fifo",
"type": "library",
"description": "Laravel SQS FIFO",
"keywords": [
"laravel",
"sqs",
"fifo"
],
"homepage": "https://culturalinfusion.org.au",
"license": "MIT",
"authors": [
{
"name": "Mohsen Sadeghzade",
"email": "mohsen.s@culturalinfusion.org.au"
"name": "culturalinfusion/laravel-sqs-fifo",
"type": "library",
"description": "Laravel SQS FIFO",
"keywords": [
"laravel",
"sqs",
"fifo"
],
"homepage": "https://culturalinfusion.org.au",
"license": "MIT",
"authors": [
{
"name": "Mohsen Sadeghzade",
"email": "mohsen.s@culturalinfusion.org.au"
},
{
"name": "Ali Bayat",
"email": "ali.b@culturalinfusion.org.au"
}
],
"support": {
"issues": "https://github.com/culturalinfusion/laravel-sqs-fifo/issues",
"source": "https://github.com/culturalinfusion/laravel-sqs-fifo"
},
{
"name": "Ali Bayat",
"email": "ali.b@culturalinfusion.org.au"
}
],
"support": {
"issues": "https://github.com/culturalinfusion/laravel-sqs-fifo/issues",
"source": "https://github.com/culturalinfusion/laravel-sqs-fifo"
},
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": "^7.2 || ^8.0",
"aws/aws-sdk-php": "^3.239",
"illuminate/queue": ">=4.1"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"orchestra/testbench": "^7.7"
},
"autoload": {
"psr-4": {
"CulturalInfusion\\LaravelSqsFifo\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"CulturalInfusion\\LaravelSqsFifo\\Tests\\": "tests/"
}
},
"extra": {
"laravel": {
"providers": [
"CulturalInfusion\\LaravelSqsFifo\\ServiceProvider"
]
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": "^8.0",
"aws/aws-sdk-php": "^3.239.9",
"illuminate/queue": "^10.44.0"
},
"require-dev": {
"phpunit/phpunit": "^10.5",
"orchestra/testbench": "^8.21"
},
"autoload": {
"psr-4": {
"CulturalInfusion\\LaravelSqsFifo\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"CulturalInfusion\\LaravelSqsFifo\\Tests\\": "tests/"
}
},
"branch-alias": {
"dev-master": "1.x-dev"
"extra": {
"laravel": {
"providers": [
"CulturalInfusion\\LaravelSqsFifo\\ServiceProvider"
]
},
"branch-alias": {
"dev-master": "1.x-dev"
}
}
}
}
3 changes: 2 additions & 1 deletion config/queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
'suffix' => env('SQS_SUFFIX'),
'queue' => env('SQS_QUEUE'),
'queue_name_prefix' => env('SQS_QUEUE_NAME_PREFIX'),
'message_group_id' => env('SQS_MESSAGE_GROUP_ID', env('SQS_PREFIX') . "/" . env('SQS_QUEUE')),
'message_group_id' => env('SQS_MESSAGE_GROUP_ID', env('SQS_ENDPOINT') . "/" . env('SQS_QUEUE')),
'region' => env('AWS_DEFAULT_REGION', 'ap-southeast-2'),
'submit_delay' => env('SQS_SUBMIT_DELAY', true) // Whether to use default delay of a Queue on Messages
]
]
];
12 changes: 6 additions & 6 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" bootstrap="vendor/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" verbose="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<testsuites>
<testsuite name="Service">
<directory suffix="Test.php">./tests</directory>
Expand All @@ -14,4 +9,9 @@
<env name="API_DEBUG" value="false"/>
<ini name="memory_limit" value="512M"/>
</php>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
3 changes: 2 additions & 1 deletion src/Services/SqsFifoConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public function connect(array $config): SqsFifoQueue
$config['prefix'] ?? '',
$config['suffix'] ?? '',
$config['message_group_id'],
$config['queue_name_prefix']
$config['queue_name_prefix'],
$config['submit_delay'] ?? true,
);
}
}
38 changes: 31 additions & 7 deletions src/Services/SqsFifoQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace CulturalInfusion\LaravelSqsFifo\Services;

use Aws\Sqs\SqsClient;
use Exception;
use BadMethodCallException;
use Illuminate\Queue\SqsQueue;

class SqsFifoQueue extends SqsQueue
Expand All @@ -23,7 +23,14 @@ class SqsFifoQueue extends SqsQueue
protected string $queue_name_prefix;

/**
* The queue name suffix.
* The flag to check whether to use default delay of the Queue on Messages.
*
* @var string
*/
protected string $submit_delay;

/**
* The queue name.
*
* @var string
*/
Expand All @@ -44,6 +51,8 @@ class SqsFifoQueue extends SqsQueue
* @param string $prefix
* @param string $suffix
* @param string $message_group_id
* @param string $queue_name_prefix
* @param bool $submit_delay
* @return void
*/
public function __construct(
Expand All @@ -52,11 +61,13 @@ public function __construct(
string $prefix = '',
string $suffix = '',
string $message_group_id = null,
string $queue_name_prefix = ''
string $queue_name_prefix = '',
bool $submit_delay = true
) {
parent::__construct($sqs, $default, $prefix);
$this->message_group_id = $message_group_id;
$this->queue_name_prefix = $queue_name_prefix;
$this->submit_delay = $submit_delay;
$this->suffix = $suffix;
}

Expand Down Expand Up @@ -94,12 +105,25 @@ public function pushRaw($payload, $queue = null, $options = []): string|null
}

/**
* SQS FIFO does not support DelaySeconds currently.
* Since SQS FIFO does not support delay per message,
* this method checks whether to apply delay value of
* the queue on the job, or throw an exception otherwise.
*
* @param \DateTime|int $delay
* @param string $job
* @param mixed $data
* @param string|null $queue
*
* @throw Exception
* @return mixed
*
* @throws BadMethodCallException
*/
public function later($delay, $job, $data = '', $queue = null): Exception
public function later($delay, $job, $data = '', $queue = null): mixed
{
throw new Exception("Cannot support DelaySeconds for FIFO queues.");
if ($this->submit_delay) {
return $this->push($job, $data, $queue);
}

throw new BadMethodCallException('SQS FIFO does not support DelaySeconds per message.');
}
}
5 changes: 2 additions & 3 deletions tests/ConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

namespace CulturalInfusion\LaravelSqsFifo\Tests;

use InvalidArgumentException;
use CulturalInfusion\LaravelSqsFifo\{Services\SqsFifoConnector, SqsFifoQueue};
use CulturalInfusion\LaravelSqsFifo\Services\{SqsFifoConnector, SqsFifoQueue};

class ConnectorTest extends TestCase
{
public function test_sqs_fifo_driver_returns_sqs_fifo_queue()
{
$config = $this->app['config']['queue.connections.sqsfifo'];
$config = $this->container['config']['queue.connections.sqsfifo'];
$connector = new SqsFifoConnector();

$connection = $connector->connect($config);
Expand Down
2 changes: 1 addition & 1 deletion tests/QueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function test_queue_sends_message_group_id()
$client->shouldReceive('sendMessage')->with(Mockery::on($closure))->andReturn($result);

$queue = new SqsFifoQueue($client, '', '', '', $group, '');
$queue->setContainer($this->app);
$queue->setContainer($this->container);

$this->assertEquals($queue->pushRaw($job), $messageId);
}
Expand Down
10 changes: 5 additions & 5 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class TestCase extends BaseTestCase
*
* @var Container
*/
protected Container $app;
protected Container $container;

/**
* The Queue Capsule instance for the tests.
Expand Down Expand Up @@ -49,9 +49,9 @@ public function setUpCapsule(): void
$queue->setAsGlobal();

$this->queue = $queue;
$this->app = $queue->getContainer();
$this->container = $queue->getContainer();

$this->app->instance('queue', $queue->getQueueManager());
$this->container->instance('queue', $queue->getQueueManager());
}

/**
Expand All @@ -61,7 +61,7 @@ public function setUpCapsule(): void
*/
public function registerServiceProvider(): void
{
$provider = new ServiceProvider($this->app);
$provider = new ServiceProvider($this->container);

$provider->register();
}
Expand Down Expand Up @@ -97,7 +97,7 @@ public function setUpQueueConnection(): void
], $connection);

$queue->getQueueManager()->addConnector($connection, function () {
return new SqsFifoConnector($this->app);
return new SqsFifoConnector($this->container);
});
}

Expand Down