Skip to content

Instantly share code, notes, and snippets.

@skunkworker
Created December 30, 2017 03:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skunkworker/772bd6475f1184ac572611e0512c1110 to your computer and use it in GitHub Desktop.
Save skunkworker/772bd6475f1184ac572611e0512c1110 to your computer and use it in GitHub Desktop.
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

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