Search code examples
ruby-on-railsrubyloggingresque

resque rails 4.2 deliver_later Mailers


I have an Ruby on Rails application where in I need to send applicant reminder mails one day prior to an interview. To do this I was planning on used The Rescue Scheduler, I am using rails v 4.2. I have run the redis server my Code is as follows:

    def sendemails
        @user2=User.new( :firstname=> "Betterlucknexttime",:email=>)
        SendEmailJob.new.perform(@user)
    end

and in the sendEmail file

    class SendEmailJob < ActiveJob::Base
        queue_as :default
        def perform(user)
            UserMailer.welcome_email(user).deliver_later
        end
    end

in config/developement I have set config.active_job.queue_adapter = :resque

I check my log file and this is what I see:

[ActiveJob] Could not log "enqueue.active_job" event. URI::GID::MissingModelIdError: Unable to create a Global ID for User without a model id. app/jobs/send_email_job.rb:5:in perform'
app/controllers/adminusers_controller.rb:45:in sendemails'

I general, when I don't use the deliver_later option, I get my emails delivered instantly. However I need to user the deliver_later to send these emails as a reminder in future. Your help is greatly appreciated!


Solution

  • Since you're doing User.new, you're not saving that user into the database. When the job gets kicked off, there is no user from the database to pull. If you do User.create instead, this should work as expected.

    Here is a link to an article describing active job and how to use it: http://www.sitepoint.com/new-rails-shiny-activejob/