Created
December 30, 2017 03:02
-
-
Save skunkworker/772bd6475f1184ac572611e0512c1110 to your computer and use it in GitHub Desktop.
ActiveJob run enqueued jobs without block for testing.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
FYI this won't work if you have jobs that are serialized with GlobalID.