Not able to send emails with .deliver_later (using DJ with ActiveJob)

1,767 views
Skip to first unread message

Dennis

unread,
Feb 12, 2015, 11:41:03 AM2/12/15
to delay...@googlegroups.com
I'm using DJ with ActiveJob. I thought I set it up correctly, but I'm not able to send mail with `deliver_later` (`deliver_now` works fine).

Here is the email delivery code:

# Before
NotificationMailer.failed_delivery(params).deliver_now

# After
NotificationMailer.failed_delivery(params).deliver_later

Here is the stack trace:

Completed 500 Internal Server Error in 21ms

 ActiveJob::SerializationError - Unsupported argument type: ActionDispatch::Http::UploadedFile:
   activejob (4.2.0) lib/active_job/arguments.rb:60:in `serialize_argument'
   activejob (4.2.0) lib/active_job/arguments.rb:57:in `block in serialize_argument'
   actionpack (4.2.0) lib/action_controller/metal/strong_parameters.rb:183:in `each_pair'
   actionpack (4.2.0) lib/action_controller/metal/strong_parameters.rb:183:in `each_pair'
   activejob (4.2.0) lib/active_job/arguments.rb:56:in `each_with_object'
   activejob (4.2.0) lib/active_job/arguments.rb:56:in `serialize_argument'
   activejob (4.2.0) lib/active_job/arguments.rb:31:in `block in serialize'
   activejob (4.2.0) lib/active_job/arguments.rb:31:in `map'
   activejob (4.2.0) lib/active_job/arguments.rb:31:in `serialize'
   activejob (4.2.0) lib/active_job/core.rb:81:in `serialize_arguments'
   activejob (4.2.0) lib/active_job/core.rb:68:in `serialize'
   activejob (4.2.0) lib/active_job/queue_adapters/delayed_job_adapter.rb:18:in `enqueue'
   activejob (4.2.0) lib/active_job/enqueuing.rb:71:in `block in enqueue'
...


My Procfile looks like:

web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
worker
: bundle exec rake jobs:work

Delayed Job is configured as follows in `config/initializers/delayed_job_config.rb`:

# https://github.com/collectiveidea/delayed_job#gory-details


Delayed::Worker.destroy_failed_jobs = false
Delayed::Worker.max_attempts = 15
Delayed::Worker.max_run_time = 1.hour
Delayed::Worker.read_ahead = 10
Delayed::Worker.sleep_delay = 6
Delayed::Worker.delay_jobs = !Rails.env.test? # Disable DJ when testing.


# Silence DJ in development (so development.log doesn't get polluted).
if Rails.env.development?
 
module Delayed
   
module Backend
     
module ActiveRecord
       
class Job
         
class << self
            alias_method
:reserve_original, :reserve
           
def reserve(worker, max_run_time = Worker.max_run_time)
              previous_level
= ::ActiveRecord::Base.logger.level
             
::ActiveRecord::Base.logger.level = Logger::WARN if previous_level < Logger::WARN
              value
= reserve_original(worker, max_run_time)
             
::ActiveRecord::Base.logger.level = previous_level
              value
           
end
         
end
       
end
     
end
   
end
 
end
end


My `config/application.rb` has the following line:

# Set ActiveJob's queueing backend to use Delayed Job.
config
.active_job.queue_adapter = :delayed_job


Any help is appreciated.

Dennis

unread,
Feb 12, 2015, 11:57:14 AM2/12/15
to delay...@googlegroups.com
I tried delaying the mail delivery without ActiveJob like

NotificationMailer.delay.failed_delivery(params)

and that worked. So the issue must be related to ActiveJob.

David Genord II

unread,
Feb 12, 2015, 2:21:28 PM2/12/15
to delay...@googlegroups.com
Your params contain a file upload and that can't be serialized into a job. Don't do that.

David Genord II

--

---
You received this message because you are subscribed to the Google Groups "delayed_job" group.
To unsubscribe from this group and stop receiving emails from it, send an email to delayed_job...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Justin Reese

unread,
May 6, 2015, 9:35:52 PM5/6/15
to delay...@googlegroups.com
Hi David. Found this thread Googling. I was hoping to use ActiveJob so I could respond before the file upload was completed. What is the right pattern here if I shouldn't/can't send an uploaded file serialized into a job?

David Genord II

unread,
May 6, 2015, 9:40:11 PM5/6/15
to delay...@googlegroups.com
You have to store the file somewhere the DJ worker can access then pass that location to the job.

David Genord II
Reply all
Reply to author
Forward
0 new messages