Skip to content

Commit

Permalink
Drop support for Laravel 6, 7, 8 and 9
Browse files Browse the repository at this point in the history
  • Loading branch information
marickvantuil committed Jan 18, 2024
1 parent ef17e01 commit 42ba247
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 179 deletions.
11 changes: 0 additions & 11 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,6 @@ jobs:
- { queue: 'github-actions-laravel10-php83', laravel: '10.*', php: '8.3', 'testbench': '8.*'}
- { queue: 'github-actions-laravel10-php82', laravel: '10.*', php: '8.2', 'testbench': '8.*'}
- { queue: 'github-actions-laravel10-php81', laravel: '10.*', php: '8.1', 'testbench': '8.*'}
- { queue: 'github-actions-laravel9-php83', laravel: '9.*', php: '8.3', 'testbench': '7.*'}
- { queue: 'github-actions-laravel9-php82', laravel: '9.*', php: '8.2', 'testbench': '7.*'}
- { queue: 'github-actions-laravel9-php81', laravel: '9.*', php: '8.1', 'testbench': '7.*'}
- { queue: 'github-actions-laravel9-php80', laravel: '9.*', php: '8.0', 'testbench': '7.*'}
- { queue: 'github-actions-laravel8-php81', laravel: '8.*', php: '8.1', 'testbench': '6.*'}
- { queue: 'github-actions-laravel8-php80', laravel: '8.*', php: '8.0', 'testbench': '6.*'}
- { queue: 'github-actions-laravel8-php74', laravel: '8.*', php: '7.4', 'testbench': '6.*'}
- { queue: 'github-actions-laravel7-php80', laravel: '7.*', php: '8.0', 'testbench': '5.*' }
- { queue: 'github-actions-laravel7-php74', laravel: '7.*', php: '7.4', 'testbench': '5.*' }
- { queue: 'github-actions-laravel6-php80', laravel: '6.*', php: '8.0', 'testbench': '4.*' }
- { queue: 'github-actions-laravel6-php74', laravel: '6.*', php: '7.4', 'testbench': '4.*' }

name: PHP ${{ matrix.payload.php }} - Laravel ${{ matrix.payload.laravel }} - DB ${{ matrix.db }}

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ This package allows Google Cloud Tasks to be used as the queue driver.
</summary>

<br>
This package requires Laravel 6 or higher and supports MySQL 8 and PostgreSQL 14. Might support older database versions too, but package hasn't been tested for it.
This package requires Laravel 10 or higher and supports MySQL 8 and PostgreSQL 15. Might support older database versions too, but package hasn't been tested for it.

Please check the [Laravel support policy](https://laravel.com/docs/master/releases#support-policy) table for supported Laravel and PHP versions.
</details>
Expand Down
18 changes: 1 addition & 17 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"thecodingmachine/safe": "^1.0|^2.0"
},
"require-dev": {
"orchestra/testbench": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0",
"orchestra/testbench": "^8.0",
"nunomaduro/larastan": "^1.0 || ^2.0",
"thecodingmachine/phpstan-safe-rule": "^1.2",
"laravel/legacy-factories": "^1.3"
Expand Down Expand Up @@ -45,21 +45,5 @@
"composer require laravel/framework:10.* orchestra/testbench:8.* --no-interaction --no-update",
"composer update --prefer-stable --prefer-dist --no-interaction"
],
"l9": [
"composer require laravel/framework:9.* orchestra/testbench:7.* --no-interaction --no-update",
"composer update --prefer-stable --prefer-dist --no-interaction"
],
"l8": [
"composer require laravel/framework:8.* orchestra/testbench:6.* --no-interaction --no-update",
"composer update --prefer-stable --prefer-dist --no-interaction"
],
"l7": [
"composer require laravel/framework:7.* orchestra/testbench:5.* --no-interaction --no-update",
"composer update --prefer-stable --prefer-dist --no-interaction"
],
"l6": [
"composer require laravel/framework:6.* orchestra/testbench:4.* --no-interaction --no-update",
"composer update --prefer-stable --prefer-dist --no-interaction"
]
}
}
11 changes: 0 additions & 11 deletions src/CloudTasksJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Illuminate\Contracts\Queue\Job as JobContract;
use Illuminate\Queue\Jobs\Job as LaravelJob;
use Stackkit\LaravelGoogleCloudTasksQueue\Events\JobReleased;
use Stackkit\LaravelGoogleCloudTasksQueue\Events\JobReleasedAfterException;
use function Safe\json_encode;

class CloudTasksJob extends LaravelJob implements JobContract
Expand Down Expand Up @@ -137,16 +136,6 @@ public function release($delay = 0)
$properties = TaskHandler::getCommandProperties($this->job['data']['command']);
$connection = $properties['connection'] ?? config('queue.default');

// The package uses the JobReleasedAfterException provided by Laravel to grab
// the payload of the released job in tests to easily run and test a released
// job. Because the event is only accessible in Laravel 9.x, we create an
// identical event to hook into for Laravel versions older than 9.x
if (version_compare(app()->version(), '9.0.0', '<')) {
if (data_get($this->job, 'internal.errored')) {
app('events')->dispatch(new JobReleasedAfterException($connection, $this));
}
}

if (! data_get($this->job, 'internal.errored')) {
app('events')->dispatch(new JobReleased($connection, $this, $delay));
}
Expand Down
33 changes: 0 additions & 33 deletions src/CloudTasksQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,6 @@ public function size($queue = null)
return 0;
}

/**
* Fallback method for Laravel 6x and 7x
*
* @param \Closure|string|object $job
* @param string $payload
* @param string $queue
* @param \DateTimeInterface|\DateInterval|int|null $delay
* @param callable $callback
* @return mixed
*/
protected function enqueueUsing($job, $payload, $queue, $delay, $callback)
{
if (method_exists(parent::class, 'enqueueUsing')) {
return parent::enqueueUsing($job, $payload, $queue, $delay, $callback);
}

return $callback($payload, $queue, $delay);
}

/**
* Push a new job onto the queue.
*
Expand Down Expand Up @@ -142,11 +123,6 @@ protected function pushToCloudTasks($queue, $payload, $delay = 0)

$payload = json_decode($payload, true);

// Laravel 7+ jobs have a uuid, but Laravel 6 doesn't have it.
// Since we are using and expecting the uuid in some places
// we will add it manually here if it's not present yet.
$payload = $this->withUuid($payload);

// Since 3.x tasks are released back onto the queue after an exception has
// been thrown. This means we lose the native [X-CloudTasks-TaskRetryCount] header
// value and need to manually set and update the number of times a task has been attempted.
Expand Down Expand Up @@ -183,15 +159,6 @@ protected function pushToCloudTasks($queue, $payload, $delay = 0)
return $payload['uuid'];
}

private function withUuid(array $payload): array
{
if (!isset($payload['uuid'])) {
$payload['uuid'] = (string) Str::uuid();
}

return $payload;
}

private function taskName(string $queueName, array $payload): string
{
$displayName = $this->sanitizeTaskName($payload['displayName']);
Expand Down
37 changes: 0 additions & 37 deletions src/Events/JobReleasedAfterException.php

This file was deleted.

6 changes: 3 additions & 3 deletions src/TaskHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ public function getWorkerOptions(): WorkerOptions
{
$options = new WorkerOptions();

$prop = version_compare(app()->version(), '8.0.0', '<') ? 'delay' : 'backoff';

$options->$prop = $this->config['backoff'] ?? 0;
if (isset($this->config['backoff'])) {
$options->backoff = $this->config['backoff'];
}

return $options;
}
Expand Down
16 changes: 5 additions & 11 deletions tests/CloudTasksDashboardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -487,17 +487,11 @@ public function test_publish()
// Act & Assert
$expectedPublishBase = dirname(__DIR__);

if (version_compare(app()->version(), '9.0.0', '>=')) {
$this->artisan('vendor:publish --tag=cloud-tasks --force')
->expectsOutputToContain('Publishing [cloud-tasks] assets.')
->expectsOutputToContain('Copying file [' . $expectedPublishBase . '/config/cloud-tasks.php] to [config/cloud-tasks.php]')
->expectsOutputToContain('Copying directory [' . $expectedPublishBase . '/dashboard/dist] to [public/vendor/cloud-tasks]');
} else {
$this->artisan('vendor:publish --tag=cloud-tasks --force')
->expectsOutput('Copied File [' . $expectedPublishBase . '/config/cloud-tasks.php] To [/config/cloud-tasks.php]')
->expectsOutput('Copied Directory [' . $expectedPublishBase . '/dashboard/dist] To [/public/vendor/cloud-tasks]')
->expectsOutput('Publishing complete.');
}
$this->artisan('vendor:publish --tag=cloud-tasks --force')
->expectsOutputToContain('Publishing [cloud-tasks] assets.')
->expectsOutputToContain('Copying file [' . $expectedPublishBase . '/config/cloud-tasks.php] to [config/cloud-tasks.php]')
->expectsOutputToContain('Copying directory [' . $expectedPublishBase . '/dashboard/dist] to [public/vendor/cloud-tasks]');

}

/**
Expand Down
28 changes: 8 additions & 20 deletions tests/QueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Illuminate\Queue\Events\JobProcessed;
use Illuminate\Queue\Events\JobProcessing;
use Illuminate\Queue\Events\JobQueued;
use Illuminate\Queue\Events\JobReleasedAfterException;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Event;
Expand Down Expand Up @@ -176,10 +177,6 @@ public function it_posts_the_task_the_correct_queue()
*/
public function it_can_dispatch_after_commit_inline()
{
if (version_compare(app()->version(), '8.0.0', '<')) {
$this->markTestSkipped('Not supported by Laravel 7.x and below.');
}

// Arrange
CloudTasksApi::fake();
Event::fake();
Expand All @@ -202,10 +199,6 @@ public function it_can_dispatch_after_commit_inline()
*/
public function it_can_dispatch_after_commit_through_config()
{
if (version_compare(app()->version(), '8.0.0', '<')) {
$this->markTestSkipped('Not supported by Laravel 7.x and below.');
}

// Arrange
CloudTasksApi::fake();
Event::fake();
Expand Down Expand Up @@ -233,15 +226,15 @@ public function jobs_can_be_released()
CloudTasksApi::fake();
OpenIdVerificator::fake();
Event::fake([
$this->getJobReleasedAfterExceptionEvent(),
JobReleasedAfterException::class,
JobReleased::class,
]);

// Act
$this->dispatch(new JobThatWillBeReleased())->run();

// Assert
Event::assertNotDispatched($this->getJobReleasedAfterExceptionEvent());
Event::assertNotDispatched(JobReleasedAfterException::class);
CloudTasksApi::assertDeletedTaskCount(0); // it returned 200 OK so we dont delete it, but Google does
$releasedJob = null;
Event::assertDispatched(JobReleased::class, function (JobReleased $event) use (&$releasedJob) {
Expand Down Expand Up @@ -275,7 +268,7 @@ public function jobs_can_be_released_with_a_delay()
CloudTasksApi::fake();
OpenIdVerificator::fake();
Event::fake([
$this->getJobReleasedAfterExceptionEvent(),
JobReleasedAfterException::class,
JobReleased::class,
]);
Carbon::setTestNow(now()->addDay());
Expand All @@ -302,7 +295,7 @@ public function test_default_backoff()
// Arrange
CloudTasksApi::fake();
OpenIdVerificator::fake();
Event::fake($this->getJobReleasedAfterExceptionEvent());
Event::fake(JobReleasedAfterException::class);

// Act
$this->dispatch(new FailingJob())->run();
Expand All @@ -321,7 +314,7 @@ public function test_backoff_from_queue_config()
$this->setConfigValue('backoff', 123);
CloudTasksApi::fake();
OpenIdVerificator::fake();
Event::fake($this->getJobReleasedAfterExceptionEvent());
Event::fake(JobReleasedAfterException::class);

// Act
$this->dispatch(new FailingJob())->run();
Expand All @@ -340,12 +333,11 @@ public function test_backoff_from_job()
Carbon::setTestNow(now()->addDay());
CloudTasksApi::fake();
OpenIdVerificator::fake();
Event::fake($this->getJobReleasedAfterExceptionEvent());
Event::fake(JobReleasedAfterException::class);

// Act
$failingJob = new FailingJob();
$prop = version_compare(app()->version(), '8.0.0', '<') ? 'delay' : 'backoff';
$failingJob->$prop = 123;
$failingJob->backoff = 123;
$this->dispatch($failingJob)->run();

// Assert
Expand All @@ -358,10 +350,6 @@ public function test_backoff_from_job()
/** @test */
public function test_exponential_backoff_from_job_method()
{
if (version_compare(app()->version(), '8.0.0', '<')) {
$this->markTestSkipped('Not supported by Laravel 7.x and below.');
}

// Arrange
Carbon::setTestNow(now()->addDay());
CloudTasksApi::fake();
Expand Down
Loading

0 comments on commit 42ba247

Please sign in to comment.