[ rails ] delayed_job

Job

NewsletterJob = Struct.new(:text, :emails) do
def perform
emails.each { |e| NewsletterMailer.deliver_text_to_email(text, e) }
end
end

Queue

Delayed::Job.enqueue NewsletterJob.new('lorem ipsum...', Customers.pluck(:email))

NOTE : this will insert into delayed_jobs table.

Run in realtime in the same thread within rspec

Delayed::Worker.new.work_off

NOTE : If you are trying to test for timing errors, race conditions, etc, this approach won’t help (since the jobs are processed in the same thread as RSpec).

ref : https://github.com/collectiveidea/delayed_job,

https://stackoverflow.com/questions/3191900/delayed-job-not-processed-in-rspec

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s