Page MenuHomePhorge

D5128.1775325445.diff
No OneTemporary

Authored By
Unknown
Size
13 KB
Referenced Files
None
Subscribers
None

D5128.1775325445.diff

diff --git a/src/app/Enums/Queue.php b/src/app/Enums/Queue.php
new file mode 100644
--- /dev/null
+++ b/src/app/Enums/Queue.php
@@ -0,0 +1,22 @@
+<?php
+
+namespace App\Enums;
+
+/**
+ * Enumeration of existing queues
+ */
+enum Queue: string
+{
+ // Note: The order defines queues priority
+ case Default = 'default';
+ case Mail = 'mail';
+ case Background = 'background';
+
+ /**
+ * Get all cases' values
+ */
+ public static function values(): array
+ {
+ return array_map(fn ($case) => $case->value, self::cases());
+ }
+}
diff --git a/src/app/Jobs/Mail/PasswordResetJob.php b/src/app/Jobs/Mail/PasswordResetJob.php
--- a/src/app/Jobs/Mail/PasswordResetJob.php
+++ b/src/app/Jobs/Mail/PasswordResetJob.php
@@ -21,7 +21,6 @@
public function __construct(VerificationCode $code)
{
$this->code = $code;
- $this->onQueue(self::QUEUE);
}
/**
diff --git a/src/app/Jobs/Mail/PasswordRetentionJob.php b/src/app/Jobs/Mail/PasswordRetentionJob.php
--- a/src/app/Jobs/Mail/PasswordRetentionJob.php
+++ b/src/app/Jobs/Mail/PasswordRetentionJob.php
@@ -25,7 +25,6 @@
{
$this->user = $user;
$this->expiresOn = $expiresOn;
- $this->onQueue(self::QUEUE);
}
/**
diff --git a/src/app/Jobs/Mail/PaymentJob.php b/src/app/Jobs/Mail/PaymentJob.php
--- a/src/app/Jobs/Mail/PaymentJob.php
+++ b/src/app/Jobs/Mail/PaymentJob.php
@@ -26,7 +26,6 @@
{
$this->payment = $payment;
$this->controller = $controller;
- $this->onQueue(self::QUEUE);
}
/**
diff --git a/src/app/Jobs/Mail/PaymentMandateDisabledJob.php b/src/app/Jobs/Mail/PaymentMandateDisabledJob.php
--- a/src/app/Jobs/Mail/PaymentMandateDisabledJob.php
+++ b/src/app/Jobs/Mail/PaymentMandateDisabledJob.php
@@ -27,7 +27,6 @@
{
$this->wallet = $wallet;
$this->controller = $controller;
- $this->onQueue(self::QUEUE);
}
/**
diff --git a/src/app/Jobs/Mail/SignupInvitationJob.php b/src/app/Jobs/Mail/SignupInvitationJob.php
--- a/src/app/Jobs/Mail/SignupInvitationJob.php
+++ b/src/app/Jobs/Mail/SignupInvitationJob.php
@@ -21,7 +21,6 @@
public function __construct(SignupInvitation $invitation)
{
$this->invitation = $invitation;
- $this->onQueue(self::QUEUE);
}
/**
diff --git a/src/app/Jobs/Mail/SignupVerificationJob.php b/src/app/Jobs/Mail/SignupVerificationJob.php
--- a/src/app/Jobs/Mail/SignupVerificationJob.php
+++ b/src/app/Jobs/Mail/SignupVerificationJob.php
@@ -21,7 +21,6 @@
public function __construct(SignupCode $code)
{
$this->code = $code;
- $this->onQueue(self::QUEUE);
}
/**
diff --git a/src/app/Jobs/Mail/TrialEndJob.php b/src/app/Jobs/Mail/TrialEndJob.php
--- a/src/app/Jobs/Mail/TrialEndJob.php
+++ b/src/app/Jobs/Mail/TrialEndJob.php
@@ -21,7 +21,6 @@
public function __construct(User $account)
{
$this->account = $account;
- $this->onQueue(self::QUEUE);
}
/**
diff --git a/src/app/Jobs/MailJob.php b/src/app/Jobs/MailJob.php
--- a/src/app/Jobs/MailJob.php
+++ b/src/app/Jobs/MailJob.php
@@ -17,7 +17,9 @@
/** @var bool Delete the job if its models no longer exist. */
public $deleteWhenMissingModels = true;
- public const QUEUE = 'mail';
+ /** @var string|null The name of the queue the job should be sent to. */
+ public $queue = \App\Enums\Queue::Mail->value;
+
/**
* Number of seconds to wait before retrying the job.
diff --git a/src/app/Jobs/WalletCharge.php b/src/app/Jobs/WalletCharge.php
--- a/src/app/Jobs/WalletCharge.php
+++ b/src/app/Jobs/WalletCharge.php
@@ -6,13 +6,11 @@
class WalletCharge extends CommonJob
{
- public const QUEUE = 'background';
-
/** @var int How many times retry the job if it fails. */
public $tries = 5;
- /** @var bool Delete the job if the wallet no longer exist. */
- public $deleteWhenMissingModels = true;
+ /** @var string|null The name of the queue the job should be sent to. */
+ public $queue = \App\Enums\Queue::Background->value;
/** @var string A wallet identifier */
protected $walletId;
@@ -27,7 +25,6 @@
public function __construct(string $walletId)
{
$this->walletId = $walletId;
- $this->onQueue(self::QUEUE);
}
/**
diff --git a/src/app/Jobs/WalletCheck.php b/src/app/Jobs/WalletCheck.php
--- a/src/app/Jobs/WalletCheck.php
+++ b/src/app/Jobs/WalletCheck.php
@@ -12,13 +12,11 @@
public const THRESHOLD_REMINDER = 'reminder';
public const THRESHOLD_INITIAL = 'initial';
- public const QUEUE = 'background';
-
/** @var int How many times retry the job if it fails. */
public $tries = 5;
- /** @var bool Delete the job if the wallet no longer exist. */
- public $deleteWhenMissingModels = true;
+ /** @var string|null The name of the queue the job should be sent to. */
+ public $queue = \App\Enums\Queue::Background->value;
/** @var ?Wallet A wallet object */
protected $wallet;
@@ -37,7 +35,6 @@
public function __construct(string $walletId)
{
$this->walletId = $walletId;
- $this->onQueue(self::QUEUE);
}
/**
diff --git a/src/config/horizon.php b/src/config/horizon.php
--- a/src/config/horizon.php
+++ b/src/config/horizon.php
@@ -1,11 +1,6 @@
<?php
-// Prioritized list of all queues
-$queues = [
- 'default',
- App\Jobs\MailJob::QUEUE,
- App\Jobs\WalletCheck::QUEUE,
-];
+use App\Enums\Queue;
return [
@@ -151,7 +146,7 @@
'production' => [
'supervisor-1' => [
'connection' => 'redis',
- 'queue' => $queues,
+ 'queue' => Queue::values(),
'balance' => 'auto',
'maxProcesses' => 1,
'minProcesses' => 1,
@@ -162,7 +157,7 @@
'local' => [
'supervisor-1' => [
'connection' => 'redis',
- 'queue' => $queues,
+ 'queue' => Queue::values(),
'balance' => 'auto',
'maxProcesses' => 1,
'minProcesses' => 1,
diff --git a/src/tests/Feature/Jobs/Mail/PasswordResetJobTest.php b/src/tests/Feature/Jobs/Mail/PasswordResetJobTest.php
--- a/src/tests/Feature/Jobs/Mail/PasswordResetJobTest.php
+++ b/src/tests/Feature/Jobs/Mail/PasswordResetJobTest.php
@@ -7,6 +7,7 @@
use App\User;
use App\VerificationCode;
use Illuminate\Support\Facades\Mail;
+use Illuminate\Support\Facades\Queue;
use Tests\TestCase;
class PasswordResetJobTest extends TestCase
@@ -52,8 +53,6 @@
$job = new PasswordResetJob($code);
$job->handle();
- $this->assertSame(PasswordResetJob::QUEUE, $job->queue);
-
// Assert the email sending job was pushed once
Mail::assertSent(PasswordReset::class, 1);
@@ -67,5 +66,10 @@
return $mail->hasFrom(\config('mail.sender.address'), \config('mail.sender.name'))
&& $mail->hasReplyTo(\config('mail.replyto.address'), \config('mail.replyto.name'));
});
+
+ // Test that the job is dispatched to the proper queue
+ Queue::fake();
+ PasswordResetJob::dispatch($code);
+ Queue::assertPushedOn(\App\Enums\Queue::Mail->value, PasswordResetJob::class);
}
}
diff --git a/src/tests/Feature/Jobs/Mail/PasswordRetentionJobTest.php b/src/tests/Feature/Jobs/Mail/PasswordRetentionJobTest.php
--- a/src/tests/Feature/Jobs/Mail/PasswordRetentionJobTest.php
+++ b/src/tests/Feature/Jobs/Mail/PasswordRetentionJobTest.php
@@ -47,7 +47,6 @@
$job = new PasswordRetentionJob($user, $expiresOn);
$job->handle();
- $this->assertSame(PasswordRetentionJob::QUEUE, $job->queue);
$this->assertMatchesRegularExpression(
'/^' . now()->format('Y-m-d') . ' [0-9]{2}:[0-9]{2}:[0-9]{2}$/',
$user->getSetting('password_expiration_warning')
diff --git a/src/tests/Feature/Jobs/Mail/PaymentJobTest.php b/src/tests/Feature/Jobs/Mail/PaymentJobTest.php
--- a/src/tests/Feature/Jobs/Mail/PaymentJobTest.php
+++ b/src/tests/Feature/Jobs/Mail/PaymentJobTest.php
@@ -63,8 +63,6 @@
$job = new PaymentJob($payment);
$job->handle();
- $this->assertSame(PaymentJob::QUEUE, $job->queue);
-
// Assert the email sending job was pushed once
Mail::assertSent(PaymentSuccess::class, 1);
diff --git a/src/tests/Feature/Jobs/Mail/PaymentMandateDisabledJobTest.php b/src/tests/Feature/Jobs/Mail/PaymentMandateDisabledJobTest.php
--- a/src/tests/Feature/Jobs/Mail/PaymentMandateDisabledJobTest.php
+++ b/src/tests/Feature/Jobs/Mail/PaymentMandateDisabledJobTest.php
@@ -48,8 +48,6 @@
$job = new PaymentMandateDisabledJob($wallet);
$job->handle();
- $this->assertSame(PaymentMandateDisabledJob::QUEUE, $job->queue);
-
// Assert the email sending job was pushed once
Mail::assertSent(PaymentMandateDisabled::class, 1);
diff --git a/src/tests/Feature/Jobs/Mail/SignupInvitationJobTest.php b/src/tests/Feature/Jobs/Mail/SignupInvitationJobTest.php
--- a/src/tests/Feature/Jobs/Mail/SignupInvitationJobTest.php
+++ b/src/tests/Feature/Jobs/Mail/SignupInvitationJobTest.php
@@ -47,8 +47,6 @@
$job = new SignupInvitationJob($this->invitation);
$job->handle();
- $this->assertSame(SignupInvitationJob::QUEUE, $job->queue);
-
// Assert the email sending job was pushed once
Mail::assertSent(SignupInvitation::class, 1);
@@ -59,12 +57,4 @@
$this->assertTrue($this->invitation->isSent());
}
-
- /**
- * Test job failure handling
- */
- public function testFailure(): void
- {
- $this->markTestIncomplete();
- }
}
diff --git a/src/tests/Feature/Jobs/Mail/SignupVerificationJobTest.php b/src/tests/Feature/Jobs/Mail/SignupVerificationJobTest.php
--- a/src/tests/Feature/Jobs/Mail/SignupVerificationJobTest.php
+++ b/src/tests/Feature/Jobs/Mail/SignupVerificationJobTest.php
@@ -55,8 +55,6 @@
$job = new SignupVerificationJob($code);
$job->handle();
- $this->assertSame(SignupVerificationJob::QUEUE, $job->queue);
-
// Assert the email sending job was pushed once
Mail::assertSent(SignupVerification::class, 1);
diff --git a/src/tests/Feature/Jobs/Mail/TrialEndJobTest.php b/src/tests/Feature/Jobs/Mail/TrialEndJobTest.php
--- a/src/tests/Feature/Jobs/Mail/TrialEndJobTest.php
+++ b/src/tests/Feature/Jobs/Mail/TrialEndJobTest.php
@@ -47,8 +47,6 @@
$job = new TrialEndJob($user);
$job->handle();
- $this->assertSame(TrialEndJob::QUEUE, $job->queue);
-
// Assert the email sending job was pushed once
Mail::assertSent(TrialEnd::class, 1);
diff --git a/src/tests/Feature/Jobs/User/UpdateTest.php b/src/tests/Feature/Jobs/User/UpdateTest.php
--- a/src/tests/Feature/Jobs/User/UpdateTest.php
+++ b/src/tests/Feature/Jobs/User/UpdateTest.php
@@ -3,6 +3,7 @@
namespace Tests\Feature\Jobs\User;
use App\Backends\LDAP;
+use App\Jobs\User\UpdateJob;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;
@@ -56,7 +57,7 @@
$user->setAliases($aliases);
- $job = new \App\Jobs\User\UpdateJob($user->id);
+ $job = new UpdateJob($user->id);
$job->handle();
if (\config('app.with_ldap')) {
@@ -72,7 +73,7 @@
$user->setAliases($aliases);
- $job = new \App\Jobs\User\UpdateJob($user->id);
+ $job = new UpdateJob($user->id);
$job->handle();
if (\config('app.with_ldap')) {
@@ -85,7 +86,7 @@
$aliases = [];
$user->setAliases($aliases);
- $job = new \App\Jobs\User\UpdateJob($user->id);
+ $job = new UpdateJob($user->id);
$job->handle();
if (\config('app.with_ldap')) {
@@ -96,7 +97,7 @@
// Test deleted user
$user->delete();
- $job = new \App\Jobs\User\UpdateJob($user->id);
+ $job = new UpdateJob($user->id);
$job->handle();
$this->assertTrue($job->isDeleted());
@@ -104,7 +105,7 @@
// Test job failure (user unknown)
// The job will be released
$this->expectException(\Exception::class);
- $job = new \App\Jobs\User\UpdateJob(123);
+ $job = new UpdateJob(123);
$job->handle();
$this->assertTrue($job->isReleased());
diff --git a/src/tests/Feature/Jobs/WalletCheckTest.php b/src/tests/Feature/Jobs/WalletCheckTest.php
--- a/src/tests/Feature/Jobs/WalletCheckTest.php
+++ b/src/tests/Feature/Jobs/WalletCheckTest.php
@@ -33,6 +33,18 @@
parent::tearDown();
}
+ /**
+ * Test job's queue assignment on dispatch
+ */
+ public function testDispatchQueue(): void
+ {
+ // Test that the job is dispatched to the proper queue
+ Queue::fake();
+ $user = $this->getTestUser('jack@kolab.org');
+ WalletCheck::dispatch($user->wallets()->first()->id);
+ Queue::assertPushedOn(\App\Enums\Queue::Background->value, WalletCheck::class);
+ }
+
/**
* Test job handle, initial negative-balance notification
*/
@@ -50,7 +62,7 @@
$job->handle();
// Ensure the job ends up on the correct queue
- $this->assertSame(WalletCheck::QUEUE, $job->queue);
+ $this->assertSame(\App\Enums\Queue::Background->value, $job->queue);
Mail::assertNothingSent();

File Metadata

Mime Type
text/plain
Expires
Sat, Apr 4, 5:57 PM (18 h, 30 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18828602
Default Alt Text
D5128.1775325445.diff (13 KB)

Event Timeline