Skip to content

Instantly share code, notes, and snippets.

@westonganger
Created August 31, 2021 03:49
Show Gist options
  • Save westonganger/14d9db2e7bb1bcce13c9099426019883 to your computer and use it in GitHub Desktop.
Save westonganger/14d9db2e7bb1bcce13c9099426019883 to your computer and use it in GitHub Desktop.
Rails Async Job Toggler
# if defined?(Sidekiq) || ["", "inline"].exclude?(Rails.application.config.active_job.queue_adapter.to_s)
if Rails.env.development?
ASYNC_JOBS = false ### change temporarily for testing
elsif Rails.env.test?
ASYNC_JOBS = false
else
ASYNC_JOBS = true
end
class ApplicationJob
if ASYNC_JOBS
include Sidekiq::Worker # if using sidekiq
else
def self.perform_async(*args)
self.new.perform(*args)
end
def self.perform_in(interval, *args)
self.new.perform(*args)
end
def self.sidekiq_options(**args)
# Do nothing, only required for Sidekiq jobs
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment