Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/Constraints/AfterConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down
8 changes: 7 additions & 1 deletion src/Jobs/SendMailJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
43 changes: 43 additions & 0 deletions tests/Feature/AfterConstraintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
);
}
}
Loading