Search code examples
ruby-on-railsruby-on-rails-3.2actionmailerdelayed-job

Why is one and only one of my ActionMailer mailers failing to send using DelayedJob


I have a mailer class with four actions. I am using DelayedJob to process all of my mailers in the background. They are all working flawlessly except one. The error I get from my worker is:

Class#exit failed with ArgumentError: wrong number of arguments (3 for 0..1)

I understand the common problem of passing an ActiveRecord::Relation object to the mailer method and I am not doing that here. If I take off the .delay() call and use the old .deliver() method, it works and sends it out, although not in the background obviously, so not ideal. Can anybody see something I may be doing wrong and overlooking?

I am using DelayedJob-3.0.5 and Rails 3.2.11.

class AdminMailer < ActionMailer::Base
  default :from => "[email protected]"

  def exit(customer, user, exit_reason)
    @customer = customer
    @user = user
    @exit_reason = exit_reason

    mail(to: "[email protected]", subject: "#{customer.business_name} canceled for this reason")
  end
end

I am calling the mailer from a controller:

class ReportsController < ApplicationController
  def exit_reason
    ct = CustomerTracking.where(customer_id: params[:customer_id]).first_or_create
    if ct.update_column(:exit_reason, params[:customer_tracking][:exit_reason]) && 
       ct.update_column(:notes, "#{ct.notes} Exit Detail: #{params[:customer_tracking][:exit_detail]}")
      flash.now[:success] = "Thank you for your answer."
    else
      flash.now[:error] = "Something went wrong!"
    end

    if params[:customer_tracking][:exit_detail].present?
      exit_detail = params[:customer_tracking][:exit_detail]
      customer = Customer.find(params[:customer_id])

      AdminMailer.delay.exit(customer, customer.user, exit_detail)
    end
  end
end

Hope this is enough information to help, thanks.


Solution

  • i think that delayed_job is confused with Kernel.exit when calling it via delay.

    i never read any remarks from delayed_job wheather this supported or not.

    if you open an issue on github about it, please link it in the comments, so that others can find the information.