Skip to content

Commit

Permalink
Support Laravel 11
Browse files Browse the repository at this point in the history
  • Loading branch information
glemoine-intouch committed May 23, 2024
1 parent 12cafbc commit 9a0fe23
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 44 deletions.
12 changes: 4 additions & 8 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,7 @@ jobs:
uses: sudo-bot/action-scrutinizer@latest
with:
cli-args: "--format=php-clover tests/reports/clover.xml --revision=${{ github.event.pull_request.head.sha || github.sha }}"
phpcs:
name: phpcs
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: php-actions/composer@v6
- name: Check PSR-12 Codestyle
run: composer check-style
pint:
uses: intouchinsight/github-workflows/.github/workflows/laravel-pint.yml@main
with:
php_version: '8.3'
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@
}
},
"require": {
"illuminate/support": "^10",
"illuminate/support": "^10.0|^11.0",
"aws/aws-sdk-php": "^3.20.6"
},
"require-dev": {
"mockery/mockery": "^1.5",
"laravel/framework": "^10",
"laravel/framework": "^10.0|^11.0",
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "^3.5",
"scrutinizer/ocular": "^1.3",
"phpstan/phpstan": "^1.9",
"nunomaduro/larastan": "^1|^2",
"orchestra/testbench": "^8"
"orchestra/testbench": "^8.0|^9.0",
"laravel/pint": "^1.16"
},
"scripts": {
"test": "phpunit",
Expand Down
9 changes: 9 additions & 0 deletions pint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"preset": "laravel",
"rules": {
"not_operator_with_successor_space": false,
"concat_space": {
"spacing": "one"
}
}
}
3 changes: 1 addition & 2 deletions src/BatchQueueServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ public function boot()
/**
* Register the Batch queue connector.
*
* @param \Illuminate\Queue\QueueManager $manager
*
* @param \Illuminate\Queue\QueueManager $manager
* @return void
*/
protected function registerBatchConnector($manager)
Expand Down
3 changes: 1 addition & 2 deletions src/Connectors/BatchConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class BatchConnector extends DatabaseConnector
/**
* Establish a queue connection.
*
* @param array $config
*
* @return \Illuminate\Contracts\Queue\Queue
*/
Expand All @@ -35,7 +34,7 @@ public function connect(array $config)
Arr::get($config, 'expire', 60),
$config['jobDefinition'],
new BatchClient([
'region' => $config['region'],
'region' => $config['region'],
'version' => '2016-08-10',
])
);
Expand Down
7 changes: 4 additions & 3 deletions src/Console/QueueWorkBatchCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@
use Illuminate\Console\Command;
use Illuminate\Contracts\Cache\Repository as Cache;
use Illuminate\Foundation\Exceptions\Handler;
use Illuminate\Queue\Console\WorkCommand;
use Illuminate\Queue\QueueManager;
use Illuminate\Queue\Worker;
use Illuminate\Queue\WorkerOptions;
use LukeWaite\LaravelQueueAwsBatch\Exceptions\JobNotFoundException;
use LukeWaite\LaravelQueueAwsBatch\Exceptions\UnsupportedException;
use LukeWaite\LaravelQueueAwsBatch\Queues\BatchQueue;
use Symfony\Component\Debug\Exception\FatalThrowableError;

class QueueWorkBatchCommand extends Command
{
Expand All @@ -38,10 +36,12 @@ class QueueWorkBatchCommand extends Command
{--force : Force the worker to run even in maintenance mode}
{--tries= : Number of times to attempt a job before logging it failed}';


protected $manager;

protected $exceptions;

protected $worker;

protected $cache;

public function __construct(QueueManager $manager, Worker $worker, Handler $exceptions, Cache $cache)
Expand Down Expand Up @@ -87,6 +87,7 @@ protected function runJob()
$job,
$this->gatherWorkerOptions()
);

return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Jobs/BatchJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class BatchJob extends DatabaseJob
*
* Here we need to retain the same jobId, so Batch can retry it, so we need to override the parent.
*
* @param int $delay
*
* @param int $delay
* @return void
*
* @throws UnsupportedException
*/
public function release($delay = 0)
Expand Down
31 changes: 15 additions & 16 deletions src/Queues/BatchQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function __construct(
public function push($job, $data = '', $queue = null)
{
$payload = $this->createPayload($job, $data);

return $this->pushToBatch($queue, $payload, $this->getBatchDisplayName($job));
}

Expand All @@ -65,7 +66,7 @@ protected function getBatchDisplayName($job)
{
if (is_object($job)) {
return method_exists($job, 'displayName')
? $job->displayName() : str_replace('\\', '_', (string)get_class($job));
? $job->displayName() : str_replace('\\', '_', (string) get_class($job));
} else {
return is_string($job) ? explode('@', $job)[0] : null;
}
Expand All @@ -74,10 +75,9 @@ protected function getBatchDisplayName($job)
/**
* Push a raw payload to the database, then to AWS Batch, with a given delay.
*
* @param string|null $queue
* @param string $payload
* @param string $jobName
*
* @param string|null $queue
* @param string $payload
* @param string $jobName
* @return int
*/
protected function pushToBatch($queue, $payload, $jobName)
Expand All @@ -86,11 +86,11 @@ protected function pushToBatch($queue, $payload, $jobName)

$this->batch->submitJob([
'jobDefinition' => $this->jobDefinition,
'jobName' => $jobName,
'jobQueue' => $this->getQueue($queue),
'parameters' => [
'jobName' => $jobName,
'jobQueue' => $this->getQueue($queue),
'parameters' => [
'jobId' => $jobId,
]
],
]);

return $jobId;
Expand All @@ -105,7 +105,6 @@ public function getJobById($id)
->where('id', $id)
->first();


if (!isset($job)) {
throw new JobNotFoundException('Could not find the job');
}
Expand Down Expand Up @@ -133,11 +132,11 @@ protected function marshalJob($queue, $job)
/**
* Release the job, without deleting first from the Queue
*
* @param string $queue
* @param \StdClass $job
* @param int $delay
*
* @param string $queue
* @param \StdClass $job
* @param int $delay
* @return int
*
* @throws UnsupportedException
*/
public function release($queue, $job, $delay)
Expand All @@ -147,8 +146,8 @@ public function release($queue, $job, $delay)
}

return $this->database->table($this->table)->where('id', $job->id)->update([
'attempts' => $job->attempts,
'reserved_at' => null
'attempts' => $job->attempts,
'reserved_at' => null,
]);
}

Expand Down
6 changes: 3 additions & 3 deletions tests/BatchJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
namespace LukeWaite\LaravelQueueAwsBatch\Tests;

use LukeWaite\LaravelQueueAwsBatch\Exceptions\UnsupportedException;
use Mockery as m;
use Mockery\Adapter\Phpunit\MockeryTestCase as TestCase;
use Mockery as m;

class BatchJobTest extends TestCase
{
public function setUp() : void
public function setUp(): void
{
$this->job = new \stdClass();
$this->job->payload = '{"job":"foo","data":["data"]}';
Expand All @@ -22,7 +22,7 @@ public function setUp() : void
$this->batchQueue = m::mock('LukeWaite\LaravelQueueAwsBatch\Queues\BatchQueue'),
$this->job,
'testConnection',
'defaultQueue'
'defaultQueue',
])->getMock();
}

Expand Down
10 changes: 5 additions & 5 deletions tests/BatchQueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@

use Carbon\Carbon;
use LukeWaite\LaravelQueueAwsBatch\Exceptions\UnsupportedException;
use Mockery as m;
use Mockery\Adapter\Phpunit\MockeryTestCase as TestCase;
use Mockery as m;

class BatchQueueTest extends TestCase
{
public function setUp() : void
public function setUp(): void
{
$this->queue = $this->getMockBuilder('LukeWaite\LaravelQueueAwsBatch\Queues\BatchQueue')->setMethods(null)->setConstructorArgs([
$this->database = m::mock('Illuminate\Database\Connection'),
'table',
'default',
'60',
'jobdefinition',
$this->batch = m::mock('Aws\Batch\BatchClient')
$this->batch = m::mock('Aws\Batch\BatchClient'),
])->getMock();

$this->queue->setContainer(m::mock('Illuminate\Container\Container'));
Expand Down Expand Up @@ -80,7 +80,7 @@ public function testGetJobById()
$queryResult->id = 1;

$table->shouldReceive('where')->once()->with('id', 1)->andReturn($reserved = m::mock('StdClass'));
$reserved->shouldReceive('update')->with(['reserved_at'=> 1473004800, 'attempts'=> 1])->once()->andReturn($job = m::mock('StdClass'));
$reserved->shouldReceive('update')->with(['reserved_at' => 1473004800, 'attempts' => 1])->once()->andReturn($job = m::mock('StdClass'));

$this->database->shouldReceive('commit')->once();

Expand All @@ -94,7 +94,7 @@ public function testRelease()
$this->database->shouldReceive('table')->once()->with('table')->andReturn($table = m::mock('StdClass'));
$table->shouldReceive('where')->once()->with('id', 4)->andReturn($query = m::mock('StdClass'));
$query->shouldReceive('update')->once()->with([
'attempts' => 1,
'attempts' => 1,
'reserved_at' => null,
])->andReturn(4);

Expand Down

0 comments on commit 9a0fe23

Please sign in to comment.