Class: Modulorails::SidekiqGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Modulorails::SidekiqGenerator
- Defined in:
- lib/generators/modulorails/sidekiq/sidekiq_generator.rb
Instance Method Summary collapse
- #add_entrypoint ⇒ Object
- #add_health_check ⇒ Object
- #add_initializer ⇒ Object
- #add_routes ⇒ Object
- #add_to_config ⇒ Object
- #add_to_deploy_files ⇒ Object
- #add_to_docker_compose ⇒ Object
- #add_to_docker_compose_prod ⇒ Object
- #add_to_gemfile ⇒ Object
Instance Method Details
#add_entrypoint ⇒ Object
95 96 97 98 |
# File 'lib/generators/modulorails/sidekiq/sidekiq_generator.rb', line 95 def add_entrypoint template 'entrypoints/sidekiq-entrypoint.sh' chmod 'entrypoints/sidekiq-entrypoint.sh', 0755 end |
#add_health_check ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/generators/modulorails/sidekiq/sidekiq_generator.rb', line 63 def add_health_check file_path = Rails.root.join('config/initializers/health_check.rb') unless File.read(file_path).match?(%r{add_custom_check\s*\(?\s*['"]sidekiq-queues['"]\s*\)?}) inject_into_file file_path, after: /^HealthCheck.setup do \|config\|\n$/ do <<-RUBY # Add one or more custom checks that return a blank string if ok, or an error message if there is an error config.add_custom_check('sidekiq-queues') do queues = Sidekiq::Queue.all # No queues, means no jobs, ok! next '' if queues.empty? enqueued_jobs_count = queues.each.map { |queue| queue.count }.sum # Less than 200 enqueued jobs, ok! enqueued_jobs_count < 200 ? '' : "\#{enqueued_jobs_count} are currently enqueued." end # Add one or more custom checks that return a blank string if ok, or an error message if there is an error config.add_custom_check('sidekiq-retries') do retry_jobs_count = Sidekiq::RetrySet.new.count # Less than 200 jobs to retry, ok! retry_jobs_count < 200 ? '' : "\#{retry_jobs_count} are waiting for retry." end RUBY end end end |
#add_initializer ⇒ Object
45 46 47 |
# File 'lib/generators/modulorails/sidekiq/sidekiq_generator.rb', line 45 def add_initializer template 'config/initializers/sidekiq.rb' end |
#add_routes ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/generators/modulorails/sidekiq/sidekiq_generator.rb', line 49 def add_routes routes_path = Rails.root.join('config/routes.rb') unless File.read(routes_path).match?(%r{require ['"]sidekiq/web["']}) inject_into_file routes_path, after: "Rails.application.routes.draw do\n" do <<-RUBY require 'sidekiq/web' mount Sidekiq::Web => '/sidekiq' RUBY end end end |
#add_to_config ⇒ Object
39 40 41 42 43 |
# File 'lib/generators/modulorails/sidekiq/sidekiq_generator.rb', line 39 def add_to_config Dir.glob(Rails.root.join('config/environments/*.rb')) do |file| add_to_config_file(file) end end |
#add_to_deploy_files ⇒ Object
19 20 21 22 23 |
# File 'lib/generators/modulorails/sidekiq/sidekiq_generator.rb', line 19 def add_to_deploy_files add_to_deploy_file(Rails.root.join('config/deploy/production.yaml')) add_to_deploy_file(Rails.root.join('config/deploy/staging.yaml')) add_to_deploy_file(Rails.root.join('config/deploy/review.yaml')) end |
#add_to_docker_compose ⇒ Object
11 12 13 |
# File 'lib/generators/modulorails/sidekiq/sidekiq_generator.rb', line 11 def add_to_docker_compose add_to_docker_compose_yml_file(Rails.root.join('docker-compose.yml')) end |
#add_to_docker_compose_prod ⇒ Object
15 16 17 |
# File 'lib/generators/modulorails/sidekiq/sidekiq_generator.rb', line 15 def add_to_docker_compose_prod add_to_docker_compose_yml_file(Rails.root.join('docker-compose.prod.yml')) end |
#add_to_gemfile ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/generators/modulorails/sidekiq/sidekiq_generator.rb', line 25 def add_to_gemfile gemfile_path = Rails.root.join('Gemfile') # Add gem redis unless already present unless File.read(gemfile_path).match?(/^\s*gem ['"]redis['"]/) append_to_file(gemfile_path, "gem 'redis'\n") end # Add gem sidekiq unless already present unless File.read(gemfile_path).match?(/^\s*gem ['"]sidekiq['"]/) append_to_file(gemfile_path, "gem 'sidekiq'\n") end end |