Search code examples
laravellaravel-5notificationsqueuejobs

How send pending notifications that are newer than 24 hours not old on restart?


Need to modify notifications so that if the notification job does not run for some reason, then when we start it up again later it only sends pending notifications that are newer than 24 hours old. Reason being, when we restart the queue, we don't want anyone getting flooded with old notifications. They are time sensitive so if we miss them, after 24 hours they just need to not be sent.

$this->dispatch(new SendOnboardingDocs($candidate));

Solution

  • You can add a retryUntil method to your job and set the timeout to 24hrs...

    /**
     * Determine the time at which the job should timeout.
     *
     * @return \DateTime
     */
    public function retryUntil()
    {
         return now()->addHours(24);
    }