From 1f284772530db42dab08a3c94cfab88048ec21a8 Mon Sep 17 00:00:00 2001 From: Frank Michel Date: Wed, 3 Dec 2025 11:16:01 +0100 Subject: [PATCH 1/3] fix: AfterConstraint diff in minutes --- src/Constraints/AfterConstraint.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Constraints/AfterConstraint.php b/src/Constraints/AfterConstraint.php index 9305932ece99..e94b105e122d 100644 --- a/src/Constraints/AfterConstraint.php +++ b/src/Constraints/AfterConstraint.php @@ -52,7 +52,7 @@ public function canSend(MailatorSchedule $schedule, Collection $logs): bool return false; } - $diff = (int) $schedule->timestamp_target->diffInHours( + $diff = (int) $schedule->timestamp_target->diffInMinutes( now()->floorSeconds(), absolute: true ); From 1be643658cd34bfe0c597d7500cd22b48c9c1282 Mon Sep 17 00:00:00 2001 From: Frank Michel Date: Wed, 3 Dec 2025 11:17:54 +0100 Subject: [PATCH 2/3] fix: added ShouldBeUnique to SendMailJob make sure that the job pushed on the queue is unique for any given mailator scheduler --- src/Jobs/SendMailJob.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Jobs/SendMailJob.php b/src/Jobs/SendMailJob.php index cf7e64afa342..e1803da1b431 100644 --- a/src/Jobs/SendMailJob.php +++ b/src/Jobs/SendMailJob.php @@ -5,12 +5,13 @@ use Binarcode\LaravelMailator\Models\MailatorSchedule; use Binarcode\LaravelMailator\Support\ClassResolver; use Illuminate\Bus\Queueable; +use Illuminate\Contracts\Queue\ShouldBeUnique; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; -class SendMailJob implements ShouldQueue +class SendMailJob implements ShouldBeUnique, ShouldQueue { use ClassResolver; use Dispatchable; @@ -32,6 +33,11 @@ public function __construct(MailatorSchedule $schedule) $this->queue = config('mailator.scheduler.send_mail_job_queue', 'default'); } + public function uniqueId(): string + { + return 'mailator-schedule-'.$this->schedule->id; + } + public function handle(): void { static::sendMailAction()->handle($this->schedule); From 3542dcef35aab774db3353df710431fd00a1c3f7 Mon Sep 17 00:00:00 2001 From: Frank Michel Date: Wed, 3 Dec 2025 11:32:44 +0100 Subject: [PATCH 3/3] added test for AfterConstraint --- tests/Feature/AfterConstraintTest.php | 43 +++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/Feature/AfterConstraintTest.php b/tests/Feature/AfterConstraintTest.php index e91f42f75e34..1d44849f7a4d 100644 --- a/tests/Feature/AfterConstraintTest.php +++ b/tests/Feature/AfterConstraintTest.php @@ -94,4 +94,47 @@ public function test_past_target_with_after_now_passed_after_constraint_hourly_b $can ); } + + public function test_past_target_with_after_now_passed_after_constraint_minutes_bases() + { + Mail::fake(); + Mail::assertNothingSent(); + + $scheduler = MailatorSchedule::init('reminder') + ->recipients('zoo@bar.com') + ->mailable( + (new InvoiceReminderMailable())->to('foo@bar.com') + ) + ->minutes(10) + ->after(now()); + + $scheduler->save(); + + $this->travelTo(now()->addMinutes(5)); + + self::assertTrue( + $scheduler->fresh()->isFutureAction() + ); + + $this->travelTo(now()->addMinutes(5)); + + self::assertTrue( + app(AfterConstraint::class) + ->canSend( + $scheduler, + $scheduler->logs + ) + ); + + $this->travelTo(now()->addMinutes(5)); + + // as long as we have passed the "after" minutes target this should return true + self::assertTrue( + app(AfterConstraint::class) + ->canSend( + $scheduler, + $scheduler->logs + ) + ); + } }