Module: Capistrano::SidekiqCommon
- Included in:
- Capistrano::Sidekiq::Systemd
- Defined in:
- lib/capistrano/sidekiq.rb
Instance Method Summary collapse
- #compiled_template_sidekiq(from, role, config_file = 'sidekiq.yml') ⇒ Object
- #expanded_bundle_command ⇒ Object
- #sidekiq_config ⇒ Object
- #sidekiq_switch_user(role, &block) ⇒ Object
- #sidekiq_user(role = nil) ⇒ Object
- #template_sidekiq(from, to, role, config_file = 'sidekiq.yml') ⇒ Object
Instance Method Details
#compiled_template_sidekiq(from, role, config_file = 'sidekiq.yml') ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/capistrano/sidekiq.rb', line 8 def compiled_template_sidekiq(from, role, config_file = 'sidekiq.yml') @role = role @config_file = config_file file = [ "lib/capistrano/templates/#{from}-#{role.hostname}-#{fetch(:stage)}.rb", "lib/capistrano/templates/#{from}-#{role.hostname}.rb", "lib/capistrano/templates/#{from}-#{fetch(:stage)}.rb", "lib/capistrano/templates/#{from}.rb.erb", "lib/capistrano/templates/#{from}.rb", "lib/capistrano/templates/#{from}.erb", "config/deploy/templates/#{from}.rb.erb", "config/deploy/templates/#{from}.rb", "config/deploy/templates/#{from}.erb", File.("../templates/#{from}.erb", __FILE__), File.("../templates/#{from}.rb.erb", __FILE__) ].detect { |path| File.file?(path) } erb = File.read(file) StringIO.new(ERB.new(erb, trim_mode: '-').result(binding)) end |
#expanded_bundle_command ⇒ Object
32 33 34 |
# File 'lib/capistrano/sidekiq.rb', line 32 def backend.capture(:echo, SSHKit.config.command_map[:bundle]).strip end |
#sidekiq_config ⇒ Object
36 37 38 |
# File 'lib/capistrano/sidekiq.rb', line 36 def sidekiq_config "--config config/#{@config_file}" if @config_file != 'sidekiq.yml' end |
#sidekiq_switch_user(role, &block) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/capistrano/sidekiq.rb', line 40 def sidekiq_switch_user(role, &block) su_user = sidekiq_user(role) if su_user == role.user yield else backend.as(su_user, &block) end end |
#sidekiq_user(role = nil) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/capistrano/sidekiq.rb', line 49 def sidekiq_user(role = nil) if role.nil? fetch(:sidekiq_user) else properties = role.properties return role.user unless properties properties.fetch(:sidekiq_user) || # local property for sidekiq only fetch(:sidekiq_user, nil) || properties.fetch(:run_as) || # global property across multiple capistrano gems role.user end end |
#template_sidekiq(from, to, role, config_file = 'sidekiq.yml') ⇒ Object
28 29 30 |
# File 'lib/capistrano/sidekiq.rb', line 28 def template_sidekiq(from, to, role, config_file = 'sidekiq.yml') backend.upload! compiled_template_sidekiq(from, role, config_file), to end |