We've moved discussions to Discord

Question about using Notified gem with Que and custom deliver_later_queue_name

Hi, Jumpstart notifications released at a perfect time for us. After spending the day playing around with the Notified gem I am really impressed with it scope and flexibility

However I ran into an issue when testing .deliver_later, where emails are not being delivered and just staying in the queue without erroring out.

Inspecting the job args in the database shows these details
{
  "job_class": "Noticed::DeliveryMethods::Email",
  "job_id": "719c3295-9a84-4f94-af27-f8602cdeaa57",
  "provider_job_id": null,
  "queue_name": "default",
  "priority": null,
  "arguments": [
  ...
}

I noticed that the queue_name is "default" . We are using Que as our worker and our deliver_later_queue_name for ActionMailer is configured as ''. Is it possible to configure the queue name that Notified uses?

I looked through the gem repo, but couldn't find anything obvious.

Chris Oliver
ActionMailer uses the mailers queue by default in Rails. 

Make sure you're also processing that queue. It's pretty common for that queue to be forgotten and emails never delivered I've noticed. 😅
Thank you for the reply Chris Oliver .

According to this blog, the following code from our application.rb should overwrite the default queue name mailers. That's for Rails 5, but I haven't been able to find anything for Rails 6 to indicate it has changed.
config.active_job.queue_adapter = :que
config.action_mailer.deliver_later_queue_name = ''

The reason for using a blank string is that is the default in Que pre v1.0 (v1.0 is still Beta, so we aren't updating yet)

I guess my first post was wrong in implying that the emails are not being sent, it's more that the Noticed::DeliveryMethod::Email job is not being run.

Running the following code creates two entries in the que_job table

class WelcomeNotification < Noticed::Base
  deliver_by :database
  deliver_by :email, mailer: 'UserMailer', method: 'welcome'

  param :user_id, :account_id

  ...
end

user = User.first
account = user.accounts.first
params = { account_id: account.id, candidate_id: candidate.id }
welcomeNotification.with(params).deliver_later(user)
UserMailer.with(params).welcome.deliver_later

The Mailer creates the below with the correct queue name
[
    {
        "job_class": "ActionMailer::MailDeliveryJob",
        "job_id": "abe27649-d224-4328-ac8a-1d5b7e00cdcc",
        "provider_job_id": null,
        "queue_name": "",
        "priority": null,
        "arguments": [
            "UserMailer",
            "welcome",
            "deliver_now",
...

The Notification creates the below with the queue name default
[
    {
        "job_class": "Noticed::DeliveryMethods::Email",
        "job_id": "4b6bd529-e7c8-4aa5-bd49-e71cce8b9e66",
        "provider_job_id": null,
        "queue_name": "default",
        "priority": null,
        "arguments": [
            {
                "notification_class": "CandidateWelcomeNotification",
                "options": {
                    "mailer": "UserMailer",
                    "method": "welcome",
...

When I start the worker, the mailer job clears and the notification job does not. I know our mailers are working fine, as they have been visibly running in production for a good two months.

I'm kind of stumped as to why this is. I know it's not anyone here's job to teach me about Rails, but I would appreciate a nudge in the right direction
I looked through the gem and realised it was inheriting from ApplicationJob, so I was able to set the queue name there. Seems this is a quirk of using Que as the queue adapter for ActiveJob. 
https://github.com/rails/rails/issues/17195
Engineering Team
Hebble and I have been diving deep into the gem and haven't found a way to configure a specific queue name to be set for a notification. As he said in the previous post, we set it up in ApplicationJob and that worked. However it seems a bit restrictive to not be able to specify the queue for each notification (or at a parent notification level for example.). 

If you think it's something useful to have in the gem, we'd love to contribute and add support for that  Chris Oliver  . Let us know and we can take the discussion to the gem's repo as an issue and start thinking of a solution.
Chris Oliver
You can change the parent class for notifications by setting Noticed.parent_class = "NotificationJob" in an initializer.

Then use the queue_as method you can dynamically change the queue based upon the notification if you want notifications in different queues.
https://api.rubyonrails.org/classes/ActiveJob/QueueName/ClassMethods.html
Chris Oliver
Might just need documenting the above in the readme, but if you can figure out a better way that can be included in the gem, that'd be awesome. 👍

Issues are always welcome to discuss ideas!
Notifications
You’re not receiving notifications from this thread.