From 553d3658a2cf12433806f475f1dd682a64624aaf Mon Sep 17 00:00:00 2001 From: Phil Reynolds Date: Fri, 11 Oct 2024 10:56:43 +0100 Subject: [PATCH 1/2] Add details about how to vary queue priority --- README.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/README.md b/README.md index 23ad63d..1079c4d 100644 --- a/README.md +++ b/README.md @@ -378,6 +378,32 @@ Each of these options are available for every delivery method (individual or bul * `config.wait_until` β€” (Should yield a specific time object) Delays the job that runs this delivery method until the specific time specified * `config.queue` β€” Sets the ActiveJob queue name to be used for the job that runs this delivery method +If you want to select the queue based on the event, for example to deliver message notifications in a high priority queue, +you can add a method to your notifier that returns the queue name. However the queue is evalutated in the context of the notification so you +must wrap it in a `notification_methods` block. + +```ruby +# app/notifiers/application_notifier.rb +class ApplicationNotifier < Noticed::Event + notification_methods do + def queue + "default" + end + end +end +# app/notifiers/message_notifier.rb +class MessageNotifier < Noticed::Event + deliver_by :delivery_method do |config| + config.queue = :queue + end + notification_methods do + def queue + "high_priority" + end + end +end +``` + ### πŸ“¨ Sending Notifications Following the `NewCommentNotifier` example above, here’s how we might invoke the Notifier to send notifications to every author in the thread about a new comment being added: From 5ced2d33d4e85a5ad2400cddd07ef8645a20dbc4 Mon Sep 17 00:00:00 2001 From: Chris Oliver Date: Mon, 14 Oct 2024 12:34:12 -0500 Subject: [PATCH 2/2] Update README.md --- README.md | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 1079c4d..2daff87 100644 --- a/README.md +++ b/README.md @@ -374,28 +374,22 @@ Each of these options are available for every delivery method (individual or bul * `config.if` β€” Intended for a lambda or method; runs after the `wait` if configured; cancels the delivery method if returns falsey * `config.unless` β€” Intended for a lambda or method; runs after the `wait` if configured; cancels the delivery method if returns truthy + +The following are evaluated in the context of the Notification so it can be customize to the recipient: + * `config.wait` β€” (Should yield an `ActiveSupport::Duration`) Delays the job that runs this delivery method for the given duration of time * `config.wait_until` β€” (Should yield a specific time object) Delays the job that runs this delivery method until the specific time specified -* `config.queue` β€” Sets the ActiveJob queue name to be used for the job that runs this delivery method +* `config.queue` β€” Sets the ActiveJob queue name to be used for the job that runs this delivery method. -If you want to select the queue based on the event, for example to deliver message notifications in a high priority queue, -you can add a method to your notifier that returns the queue name. However the queue is evalutated in the context of the notification so you -must wrap it in a `notification_methods` block. +When using a symbol, the matching method must be defined inside the `notification_methods` block: ```ruby -# app/notifiers/application_notifier.rb -class ApplicationNotifier < Noticed::Event - notification_methods do - def queue - "default" - end - end -end # app/notifiers/message_notifier.rb class MessageNotifier < Noticed::Event deliver_by :delivery_method do |config| config.queue = :queue end + notification_methods do def queue "high_priority"