Skip to content

Commit 924434c

Browse files
authored
Merge pull request #1 from intouchinsight/support-laravel-11
Support laravel 11
2 parents bd49b17 + 9a0fe23 commit 924434c

File tree

11 files changed

+64
-58
lines changed

11 files changed

+64
-58
lines changed

.github/workflows/tests.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,7 @@ jobs:
5454
uses: sudo-bot/action-scrutinizer@latest
5555
with:
5656
cli-args: "--format=php-clover tests/reports/clover.xml --revision=${{ github.event.pull_request.head.sha || github.sha }}"
57-
phpcs:
58-
name: phpcs
59-
runs-on: ubuntu-latest
60-
steps:
61-
- uses: actions/checkout@v3
62-
- uses: php-actions/composer@v6
63-
- name: Check PSR-12 Codestyle
64-
run: composer check-style
57+
pint:
58+
uses: intouchinsight/github-workflows/.github/workflows/laravel-pint.yml@main
59+
with:
60+
php_version: '8.3'

.tool-versions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
php 8.1.13
1+
php 8.3.3

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,19 @@
1919
}
2020
},
2121
"require": {
22-
"illuminate/support": "^8",
22+
"illuminate/support": "^10.0|^11.0",
2323
"aws/aws-sdk-php": "^3.20.6"
2424
},
2525
"require-dev": {
2626
"mockery/mockery": "^1.5",
27-
"laravel/framework": "^8",
27+
"laravel/framework": "^10.0|^11.0",
2828
"phpunit/phpunit": "^9.5",
2929
"squizlabs/php_codesniffer": "^3.5",
3030
"scrutinizer/ocular": "^1.3",
3131
"phpstan/phpstan": "^1.9",
3232
"nunomaduro/larastan": "^1|^2",
33-
"orchestra/testbench": "^6|^7"
33+
"orchestra/testbench": "^8.0|^9.0",
34+
"laravel/pint": "^1.16"
3435
},
3536
"scripts": {
3637
"test": "phpunit",

pint.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"preset": "laravel",
3+
"rules": {
4+
"not_operator_with_successor_space": false,
5+
"concat_space": {
6+
"spacing": "one"
7+
}
8+
}
9+
}

src/BatchQueueServiceProvider.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ public function boot()
4343
/**
4444
* Register the Batch queue connector.
4545
*
46-
* @param \Illuminate\Queue\QueueManager $manager
47-
*
46+
* @param \Illuminate\Queue\QueueManager $manager
4847
* @return void
4948
*/
5049
protected function registerBatchConnector($manager)

src/Connectors/BatchConnector.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ class BatchConnector extends DatabaseConnector
2222
/**
2323
* Establish a queue connection.
2424
*
25-
* @param array $config
2625
*
2726
* @return \Illuminate\Contracts\Queue\Queue
2827
*/
@@ -35,7 +34,7 @@ public function connect(array $config)
3534
Arr::get($config, 'expire', 60),
3635
$config['jobDefinition'],
3736
new BatchClient([
38-
'region' => $config['region'],
37+
'region' => $config['region'],
3938
'version' => '2016-08-10',
4039
])
4140
);

src/Console/QueueWorkBatchCommand.php

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,43 +15,47 @@
1515
use Illuminate\Console\Command;
1616
use Illuminate\Contracts\Cache\Repository as Cache;
1717
use Illuminate\Foundation\Exceptions\Handler;
18-
use Illuminate\Queue\Console\WorkCommand;
1918
use Illuminate\Queue\QueueManager;
2019
use Illuminate\Queue\Worker;
2120
use Illuminate\Queue\WorkerOptions;
2221
use LukeWaite\LaravelQueueAwsBatch\Exceptions\JobNotFoundException;
2322
use LukeWaite\LaravelQueueAwsBatch\Exceptions\UnsupportedException;
2423
use LukeWaite\LaravelQueueAwsBatch\Queues\BatchQueue;
25-
use Symfony\Component\Debug\Exception\FatalThrowableError;
2624

27-
class QueueWorkBatchCommand extends WorkCommand
25+
class QueueWorkBatchCommand extends Command
2826
{
2927
protected $name = 'queue:work-batch';
3028

3129
protected $description = 'Run a Job for the AWS Batch queue';
3230

3331
protected $signature = 'queue:work-batch
32+
{connection : The name of the queue connection to work}
3433
{job_id : The job id in the database}
35-
{connection? : The name of the queue connection to work}
3634
{--memory=128 : The memory limit in megabytes}
3735
{--timeout=60 : The number of seconds a child process can run}
38-
{--tries=0 : Number of times to attempt a job before logging it failed}';
39-
36+
{--force : Force the worker to run even in maintenance mode}
37+
{--tries= : Number of times to attempt a job before logging it failed}';
4038

4139
protected $manager;
40+
4241
protected $exceptions;
4342

43+
protected $worker;
44+
45+
protected $cache;
46+
4447
public function __construct(QueueManager $manager, Worker $worker, Handler $exceptions, Cache $cache)
4548
{
46-
parent::__construct($worker, $cache);
49+
parent::__construct();
50+
4751
$this->manager = $manager;
52+
$this->worker = $worker;
4853
$this->exceptions = $exceptions;
54+
$this->cache = $cache;
4955
}
5056

51-
public function fire()
57+
public function handle()
5258
{
53-
$this->listenForEvents();
54-
5559
try {
5660
$this->runJob();
5761
} catch (\Throwable $e) {
@@ -83,6 +87,7 @@ protected function runJob()
8387
$job,
8488
$this->gatherWorkerOptions()
8589
);
90+
8691
return;
8792
}
8893

@@ -98,12 +103,10 @@ protected function runJob()
98103
protected function gatherWorkerOptions()
99104
{
100105
return new WorkerOptions(
101-
0,
102-
$this->option('memory'),
103-
$this->option('timeout'),
104-
0,
105-
$this->option('tries'),
106-
false
106+
name: $this->argument('connection'),
107+
memory: $this->option('memory'),
108+
timeout: $this->option('timeout'),
109+
maxTries: $this->option('tries'),
107110
);
108111
}
109112
}

src/Jobs/BatchJob.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ class BatchJob extends DatabaseJob
2929
*
3030
* Here we need to retain the same jobId, so Batch can retry it, so we need to override the parent.
3131
*
32-
* @param int $delay
33-
*
32+
* @param int $delay
3433
* @return void
34+
*
3535
* @throws UnsupportedException
3636
*/
3737
public function release($delay = 0)

src/Queues/BatchQueue.php

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public function __construct(
4747
public function push($job, $data = '', $queue = null)
4848
{
4949
$payload = $this->createPayload($job, $data);
50+
5051
return $this->pushToBatch($queue, $payload, $this->getBatchDisplayName($job));
5152
}
5253

@@ -65,7 +66,7 @@ protected function getBatchDisplayName($job)
6566
{
6667
if (is_object($job)) {
6768
return method_exists($job, 'displayName')
68-
? $job->displayName() : str_replace('\\', '_', (string)get_class($job));
69+
? $job->displayName() : str_replace('\\', '_', (string) get_class($job));
6970
} else {
7071
return is_string($job) ? explode('@', $job)[0] : null;
7172
}
@@ -74,10 +75,9 @@ protected function getBatchDisplayName($job)
7475
/**
7576
* Push a raw payload to the database, then to AWS Batch, with a given delay.
7677
*
77-
* @param string|null $queue
78-
* @param string $payload
79-
* @param string $jobName
80-
*
78+
* @param string|null $queue
79+
* @param string $payload
80+
* @param string $jobName
8181
* @return int
8282
*/
8383
protected function pushToBatch($queue, $payload, $jobName)
@@ -86,11 +86,11 @@ protected function pushToBatch($queue, $payload, $jobName)
8686

8787
$this->batch->submitJob([
8888
'jobDefinition' => $this->jobDefinition,
89-
'jobName' => $jobName,
90-
'jobQueue' => $this->getQueue($queue),
91-
'parameters' => [
89+
'jobName' => $jobName,
90+
'jobQueue' => $this->getQueue($queue),
91+
'parameters' => [
9292
'jobId' => $jobId,
93-
]
93+
],
9494
]);
9595

9696
return $jobId;
@@ -105,7 +105,6 @@ public function getJobById($id)
105105
->where('id', $id)
106106
->first();
107107

108-
109108
if (!isset($job)) {
110109
throw new JobNotFoundException('Could not find the job');
111110
}
@@ -133,11 +132,11 @@ protected function marshalJob($queue, $job)
133132
/**
134133
* Release the job, without deleting first from the Queue
135134
*
136-
* @param string $queue
137-
* @param \StdClass $job
138-
* @param int $delay
139-
*
135+
* @param string $queue
136+
* @param \StdClass $job
137+
* @param int $delay
140138
* @return int
139+
*
141140
* @throws UnsupportedException
142141
*/
143142
public function release($queue, $job, $delay)
@@ -147,8 +146,8 @@ public function release($queue, $job, $delay)
147146
}
148147

149148
return $this->database->table($this->table)->where('id', $job->id)->update([
150-
'attempts' => $job->attempts,
151-
'reserved_at' => null
149+
'attempts' => $job->attempts,
150+
'reserved_at' => null,
152151
]);
153152
}
154153

tests/BatchJobTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
namespace LukeWaite\LaravelQueueAwsBatch\Tests;
44

55
use LukeWaite\LaravelQueueAwsBatch\Exceptions\UnsupportedException;
6-
use Mockery as m;
76
use Mockery\Adapter\Phpunit\MockeryTestCase as TestCase;
7+
use Mockery as m;
88

99
class BatchJobTest extends TestCase
1010
{
11-
public function setUp() : void
11+
public function setUp(): void
1212
{
1313
$this->job = new \stdClass();
1414
$this->job->payload = '{"job":"foo","data":["data"]}';
@@ -22,7 +22,7 @@ public function setUp() : void
2222
$this->batchQueue = m::mock('LukeWaite\LaravelQueueAwsBatch\Queues\BatchQueue'),
2323
$this->job,
2424
'testConnection',
25-
'defaultQueue'
25+
'defaultQueue',
2626
])->getMock();
2727
}
2828

0 commit comments

Comments
 (0)