Sha256: d0855df4c4177b556aefcb220ecd8927c4bf81a30e553f90a2ad2edaaf07b262

Contents?: true

Size: 1.68 KB

Versions: 2

Compression:

Stored size: 1.68 KB

Contents

# frozen_string_literal: true

require 'rails/generators'

module EIVO
  module Sidekiq
    class InstallGenerator < Rails::Generators::Base

      source_root File.expand_path('../templates', __FILE__)

      def self.namespace(name = nil)
        @namespace ||= super.sub('e_i_v_o', 'eivo')
      end

      def create_initializer_file
        copy_file 'config/sidekiq.yml'
        copy_file 'app/jobs/application_job.rb'

        restart_code = <<-'EOF'
### EIVO Sidekiq begin ###

bundle exec sidekiqctl stop tmp/pids/sidekiq.pid 120
bundle exec sidekiq -C config/sidekiq.yml

### EIVO Sidekiq end ###
EOF

        stop_code = <<-'EOF'
### EIVO Sidekiq begin ###

bundle exec sidekiqctl stop tmp/pids/sidekiq.pid 15

### EIVO Sidekiq end ###
EOF

        # Remove old code if present
        regexp = /\n### EIVO Sidekiq begin ###.*### EIVO Sidekiq end ###/m
        gsub_file 'restart_production.sh', regexp, ''
        gsub_file 'restart_staging.sh', regexp, ''
        gsub_file 'stop_production.sh', regexp, ''
        gsub_file 'stop_staging.sh', regexp, ''

        # Inject new code
        after = "### EIVO end ###\n"
        inject_into_file 'restart_production.sh', restart_code, after: after
        inject_into_file 'restart_staging.sh', restart_code, after: after
        inject_into_file 'stop_production.sh', stop_code, after: after
        inject_into_file 'stop_staging.sh', stop_code, after: after

        append_to_file 'Procfile', "worker: bundle exec sidekiq -C config/sidekiq.yml\n"
        append_to_file '.env.example', "SIDEKIQ_THREADS=\"5\"\n"
        gsub_file '.env.example', /^DB_POOL="(\d+)".*/, 'DB_POOL="\1" # [RAILS_MAX_THREADS, SIDEKIQ_THREADS].max'
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
eivo-rails-sidekiq-0.0.2 lib/generators/eivo/sidekiq/install_generator.rb
eivo-rails-sidekiq-0.0.1 lib/generators/eivo/sidekiq/install_generator.rb