Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Deprecate API that will be removed #447

Merged
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
27 changes: 27 additions & 0 deletions src/Services/AbstractQueuedJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,4 +271,31 @@ public function __get($name)
{
return isset($this->jobData->$name) ? $this->jobData->$name : null;
}

/**
* Resolves a queue name to one of the queue constants.
* If $queue is already the value of one of the constants, it will be returned.
* If the queue is unknown, `null` will be returned.
*/
public static function getQueue(string|int $queue): ?string
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need this in two places so I've abstracted it out from the task into here.

{
switch (strtolower($queue)) {
case 'immediate':
$queue = QueuedJob::IMMEDIATE;
break;
case 'queued':
$queue = QueuedJob::QUEUED;
break;
case 'large':
$queue = QueuedJob::LARGE;
break;
default:
$queue = (string) $queue;
$queues = [QueuedJob::IMMEDIATE, QueuedJob::QUEUED, QueuedJob::LARGE];
if (!ctype_digit($queue) || !in_array($queue, $queues)) {
return null;
}
}
return $queue;
GuySartorelli marked this conversation as resolved.
Show resolved Hide resolved
}
}
16 changes: 16 additions & 0 deletions src/Tasks/ProcessJobQueueChildTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@

use SilverStripe\Control\HTTPRequest;
use SilverStripe\Dev\BuildTask;
use SilverStripe\Dev\Deprecation;
use Symbiote\QueuedJobs\Services\QueuedJobService;

/**
* @deprecated 5.3.0 Will be replaced with Symbiote\QueuedJobs\Cli\ProcessJobQueueChildCommand
*/
class ProcessJobQueueChildTask extends BuildTask
{
/**
Expand All @@ -14,6 +18,18 @@ class ProcessJobQueueChildTask extends BuildTask
*/
private static $segment = 'ProcessJobQueueChildTask';

public function __construct()
{
parent::__construct();
Deprecation::withNoReplacement(function () {
Deprecation::notice(
'5.3.0',
'Will be replaced with Symbiote\QueuedJobs\Cli\ProcessJobQueueChildCommand',
Deprecation::SCOPE_CLASS
);
});
}

/**
* @param HTTPRequest $request
*/
Expand Down
7 changes: 6 additions & 1 deletion src/Tasks/ProcessJobQueueTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Core\Environment;
use SilverStripe\Dev\BuildTask;
use SilverStripe\Dev\Deprecation;
use Symbiote\QueuedJobs\Services\AbstractQueuedJob;
use Symbiote\QueuedJobs\Services\QueuedJob;
use Symbiote\QueuedJobs\Services\QueuedJobService;

Expand Down Expand Up @@ -83,7 +85,7 @@ public function run($request)
}

// Run the queue
$queue = $this->getQueue($request);
$queue = AbstractQueuedJob::getQueue($request->getVar('queue') ?? 'Queued');
GuySartorelli marked this conversation as resolved.
Show resolved Hide resolved
$service->runQueue($queue);
}

Expand All @@ -94,9 +96,12 @@ public function run($request)
*
* @param HTTPRequest $request
* @return string
* @deprecated 5.3.0 Use Symbiote\QueuedJobs\Services\AbstractQueuedJob::getQueue() instead
*/
protected function getQueue($request)
{
Deprecation::notice('5.3.0', 'Use ' . AbstractQueuedJob::class . '::getQueue() instead');

$queue = $request->getVar('queue');

if (!$queue) {
Expand Down
55 changes: 55 additions & 0 deletions tests/QueuedJobsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use SilverStripe\ORM\ValidationException;
use Symbiote\QueuedJobs\DataObjects\QueuedJobDescriptor;
use Symbiote\QueuedJobs\Jobs\RunBuildTaskJob;
use Symbiote\QueuedJobs\Services\AbstractQueuedJob;
use Symbiote\QueuedJobs\Services\QueuedJob;
use Symbiote\QueuedJobs\Services\QueuedJobService;
use Symbiote\QueuedJobs\Tests\QueuedJobsTest\TestExceptingJob;
Expand Down Expand Up @@ -830,4 +831,58 @@ public function healthCheckProvider(): array
[RunBuildTaskJob::class, 0],
];
}

public function provideGetQueue(): array
{
return [
'immediate const' => [
'queue' => QueuedJob::IMMEDIATE,
'expected' => QueuedJob::IMMEDIATE,
],
'queued const' => [
'queue' => QueuedJob::QUEUED,
'expected' => QueuedJob::QUEUED,
],
'large const' => [
'queue' => QueuedJob::LARGE,
'expected' => QueuedJob::LARGE,
],
'immediate string' => [
'queue' => 'iMmEdiAte',
'expected' => QueuedJob::IMMEDIATE,
],
'immediate as int' => [
'queue' => 1,
'expected' => QueuedJob::IMMEDIATE,
],
'queued string' => [
'queue' => 'queued',
'expected' => QueuedJob::QUEUED,
],
'large string' => [
'queue' => 'large',
'expected' => QueuedJob::LARGE,
],
'random string' => [
'queue' => 'bongos',
'expected' => null,
],
'negative int' => [
'queue' => -1,
'expected' => null,
],
'random int' => [
'queue' => 5,
'expected' => null,
],
];
}

/**
* @dataProvider provideGetQueue
*/
public function testGetQueue(int|string $queue, ?string $expected): void
{
$this->assertSame($expected, AbstractQueuedJob::getQueue($queue));
}
}
Loading