Skip to content

Commit

Permalink
Merge pull request #832 from MasoniteFramework/fix/802
Browse files Browse the repository at this point in the history
Fixed missing queable notification feature
  • Loading branch information
josephmancuso authored Oct 31, 2024
2 parents 20f6f96 + e0239a4 commit 2cafefb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
15 changes: 10 additions & 5 deletions src/masonite/notification/Notifiable.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,28 @@


class Notifiable:
"""Notifiable mixin allowing to send notification to a model. It's often used with the
"""Notifiable mixin allowing to send
notification to a model. It's often used with the
User model.
Usage:
user.notify(WelcomeNotification())
"""

def notify(self, notification, drivers=[], dry=False, fail_silently=False):
"""Send the given notification."""
from wsgi import application

if hasattr(notification, "send"):
notification.send(notification, drivers, dry, fail_silently)

return application.make("notification").send(
self, notification, drivers, dry, fail_silently
)

def route_notification_for(self, driver):
"""Get the notification routing information for the given driver. If method has not been
defined on the model: for mail driver try to use 'email' field of model."""
"""Get the notification routing information for the given driver.
If method has not been defined on the model:
for mail driver try to use 'email' field of model."""
# check if routing has been specified on the model
method_name = "route_notification_for_{0}".format(driver)

Expand All @@ -39,7 +43,8 @@ def route_notification_for(self, driver):
return self.email
else:
raise NotificationException(
"Notifiable model does not implement {}".format(method_name)
"Notifiable model "
"does not implement {}".format(method_name)
)

@has_many("id", "notifiable_id")
Expand Down
8 changes: 8 additions & 0 deletions src/masonite/queues/Queueable.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ class Queueable:
run_again_on_fail = True
run_times = 3

def queue(self):
return "default"

def handle(self):
pass

Expand All @@ -15,3 +18,8 @@ def failed(self, obj, e):

def __repr__(self):
return self.__class__.__name__

def send(self, notification, driver="", dry=False, fail_silently=False):
from ..facades.Queue import Queue
Queue.push(notification, queue=self.queue())
print('Sending to queue', notification)
5 changes: 3 additions & 2 deletions tests/integrations/notifications/OneTimePassword.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from src.masonite.notification import Notification, Textable
from src.masonite.mail import Mailable
from src.masonite.mail import Mailable
from src.masonite.queues.Queueable import Queueable


class OneTimePassword(Notification, Mailable, Textable):
class OneTimePassword(Notification, Mailable, Textable, Queueable):
def to_mail(self, notifiable):
return (
self.to(notifiable.email)
Expand All @@ -16,4 +17,4 @@ def to_vonage(self, notifiable):
return self.text_message("Welcome !").to("6314870798").from_("33123456789")

def via(self, notifiable):
return ["vonage"]
return ["mail"]

0 comments on commit 2cafefb

Please sign in to comment.