lib/potassium/recipes/background_processor.rb in potassium-6.1.0 vs lib/potassium/recipes/background_processor.rb in potassium-6.2.0

- old
+ new

@@ -1,14 +1,14 @@ class Recipes::BackgroundProcessor < Rails::AppBuilder def ask - response = if selected?(:email_service, :none) + response = if enabled_mailer? + info "Note: Emails should be sent on background jobs. We'll install sidekiq" + true + else answer(:background_processor) do Ask.confirm("Do you want to use Sidekiq for background job processing?") end - else - info "Note: Emails should be sent on background jobs. We'll install sidekiq" - true end set(:background_processor, response) end def create @@ -28,10 +28,46 @@ def installed? gem_exists?(/sidekiq/) end + def add_sidekiq + recipe = self + run_action(:install_sidekiq) do + gather_gem("sidekiq") + recipe.add_adapters("sidekiq") + add_readme_section :internal_dependencies, :sidekiq + recipe.edit_procfile("bundle exec sidekiq") + append_to_file(".env.development", "DB_POOL=25\n") + template("../assets/sidekiq.rb.erb", "config/initializers/sidekiq.rb", force: true) + copy_file("../assets/sidekiq.yml", "config/sidekiq.yml", force: true) + copy_file("../assets/redis.yml", "config/redis.yml", force: true) + recipe.mount_sidekiq_routes + end + end + + def edit_procfile(cmd) + heroku = load_recipe(:heroku) + if selected?(:heroku) || heroku.installed? + gsub_file('Procfile', /^.*$/m) { |match| "#{match}worker: #{cmd}" } + end + end + + def add_adapters(name) + application("config.active_job.queue_adapter = :#{name}") + application "config.active_job.queue_adapter = :async", env: "development" + application "config.active_job.queue_adapter = :test", env: "test" + end + + def mount_sidekiq_routes + insert_into_file "config/routes.rb", after: "Rails.application.routes.draw do\n" do + <<-HERE.gsub(/^ {6}/, '') + mount Sidekiq::Web => '/queue' + HERE + end + end + private def add_docker_compose_redis_config compose = DockerHelpers.new('docker-compose.yml') @@ -57,35 +93,10 @@ REDIS_URL=redis://${REDIS_HOST}:${REDIS_PORT}/1 TEXT ) end - def add_sidekiq - gather_gem("sidekiq") - add_adapters("sidekiq") - add_readme_section :internal_dependencies, :sidekiq - edit_procfile("bundle exec sidekiq") - append_to_file(".env.development", "DB_POOL=25\n") - template("../assets/sidekiq.rb.erb", "config/initializers/sidekiq.rb", force: true) - copy_file("../assets/sidekiq.yml", "config/sidekiq.yml", force: true) - copy_file("../assets/redis.yml", "config/redis.yml", force: true) - - insert_into_file "config/routes.rb", after: "Rails.application.routes.draw do\n" do - <<-HERE.gsub(/^ {6}/, '') - mount Sidekiq::Web => '/queue' - HERE - end - end - - def edit_procfile(cmd) - heroku = load_recipe(:heroku) - if selected?(:heroku) || heroku.installed? - gsub_file('Procfile', /^.*$/m) { |match| "#{match}worker: #{cmd}" } - end - end - - def add_adapters(name) - application("config.active_job.queue_adapter = :#{name}") - application "config.active_job.queue_adapter = :async", env: "development" - application "config.active_job.queue_adapter = :test", env: "test" + def enabled_mailer? + mailer_answer = get(:email_service) + mailer_answer && ![:none, :None].include?(mailer_answer.to_sym) end end