Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ActiveJob run enqueued jobs without block for testing.
# this pulls out each job and runs it, then clears the job queue.
# helpful when you don't want to run inside a block.
def perform_enqueued_jobs_now
enqueued_jobs = ActiveJob::Base.queue_adapter.enqueued_jobs
enqueued_jobs.each do |item|
item[:job].perform_now(*item[:args])
ActiveJob::Base.queue_adapter.performed_jobs << item
end
ActiveJob::Base.queue_adapter.enqueued_jobs.clear
end
@silvamerica
Copy link

silvamerica commented Feb 5, 2019

FYI this won't work if you have jobs that are serialized with GlobalID.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment