Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shouldRescheduleFor method (similar to shouldInterrupt) #102

Closed
cristiancalara opened this issue Oct 8, 2022 · 2 comments
Closed

Add shouldRescheduleFor method (similar to shouldInterrupt) #102

cristiancalara opened this issue Oct 8, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@cristiancalara
Copy link
Contributor

cristiancalara commented Oct 8, 2022

I'm creating a zip in AWS that might take as long as 15m. I'd like to send the notification as soon as possible, so ideally I'd check every minute, and then if it's ready I send the notification, if not, I reschedule.

I've done this by extending the custom model and overwriting the send method.

public function send(): void
{
    // ...
    if ($this->shouldInterrupt($notification, $notifiable)) {
        $this->cancel();
        event(new NotificationInterrupted($this));

        return;
    }

    if($sendAt = $this->shouldRescheduleFor($notification, $notifiable)) {
        $this->reschedule($sendAt);

        return;
    }
    // ...

}

public function shouldRescheduleFor(?object $notification = null, ?object $notifiable = null):
\DateTimeInterface|string|null
{
    if (! $notification) {
        $notification = $this->serializer->unserialize($this->notification);
    }

    if (! $notifiable) {
        $notifiable = $this->serializer->unserialize($this->target);
    }

    if (method_exists($notification, 'shouldRescheduleFor')) {
        return $notification->shouldRescheduleFor($notifiable);
    }

    return null;
}

Created the issue mainly to ask if you think this might be a useful feature for the package. If that's the case, I can create a PR for this.

Thanks for the package! :)

@atymic
Copy link
Collaborator

atymic commented Mar 20, 2024

Feel free to PR, sounds great!

@atymic atymic added the enhancement New feature or request label Mar 20, 2024
@atymic
Copy link
Collaborator

atymic commented Apr 16, 2024

Closed in #104 :D

@atymic atymic closed this as completed Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants