Maybe Ive been doing it for too long without any break, but Im banging my head as to how I can make a scheduled email to be sent in Laravel 11.
I have this:
if($document->wasRecentlyCreated) {
DocumentReviewJob::dispatch($document)->delay($document->review_at); //Example of what I want
And I want if this passes, an email to be sent at a timestamp called $document->review_at. I created a DocumentReviewJob with a $document constructor:
public function handle(): void
{
$user = User::find($this->document->author);
Mail::to($user->email)->send(new DocumentReviewReminderMail($this->document));
$this->document->update(['state' => 38]);
//Then also set a new "review_at" and create a new job that will execute at the new "review_at" time
}
But, then I need to use ->delay and that is usually short term. But then I figured, what If this mail needs to be sent in 5 years, would this even work? Answer in most cases is "no". Like, for example, the Amazon SQS queue service has a maximum delay time of 15 minutes.
What Im really asking is quite simple. I want when the $document->review_at time is reached, to send out a Mail and do some DB fidgeting. Then when that is executed, I need it to set a new $document->review_at and send another job at that new review_at time. So, kind of like a cycle/Period (I will do calculations myself, it depends on a review_cycle entry in the DB). What is the right way of doing this in Laravel 11, since there's been so much change on Queues between Laravel 10 and 11? I did also take a look at Schedules, but it was not what I needed. I come from a cakePHP environment and over there, we'd make commands and schedule CRONs, but here, its all different and works differently, or at least it seems to me.