Module: Sidekiq::HerokuAutoscale

Defined in:
lib/sidekiq/heroku_autoscale.rb,
lib/sidekiq/heroku_autoscale/process.rb,
lib/sidekiq/heroku_autoscale/version.rb,
lib/sidekiq/heroku_autoscale/heroku_app.rb,
lib/sidekiq/heroku_autoscale/middleware.rb,
lib/sidekiq/heroku_autoscale/queue_system.rb,
lib/sidekiq/heroku_autoscale/poll_interval.rb,
lib/sidekiq/heroku_autoscale/web_extension.rb,
lib/sidekiq/heroku_autoscale/scale_strategy.rb

Defined Under Namespace

Modules: WebExtension Classes: HerokuApp, Middleware, PollInterval, Process, QueueSystem, ScaleStrategy

Constant Summary collapse

VERSION =
'0.0.1'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.exception_handlerObject



58
59
60
61
62
63
# File 'lib/sidekiq/heroku_autoscale.rb', line 58

def exception_handler
  @exception_handler ||= lambda { |ex|
    p ex
    puts ex.backtrace
  }
end

Class Method Details

.appObject



13
14
15
# File 'lib/sidekiq/heroku_autoscale.rb', line 13

def app
  @app
end

.init(options) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/sidekiq/heroku_autoscale.rb', line 17

def init(options)
  options = options.transform_keys(&:to_sym)
  @app = HerokuApp.new(options)

  ::Sidekiq.logger.warn('Heroku platform API is not configured for Sidekiq::HerokuAutoscale') unless @app.live?

  # configure sidekiq queue server
  ::Sidekiq.configure_server do |config|
    config.on(:startup) do
      dyno_name = ENV['DYNO']
      next unless dyno_name

      process = @app.process_by_name(dyno_name.split('.').first)
      next unless process

      process.ping!
    end

    config.server_middleware do |chain|
      chain.add(Middleware, @app)
    end

    # for jobs that queue other jobs...
    config.client_middleware do |chain|
      chain.add(Middleware, @app)
    end
  end

  # configure sidekiq app client
  ::Sidekiq.configure_client do |config|
    config.client_middleware do |chain|
      chain.add(Middleware, @app)
    end
  end

  # immedaitely wake all processes during client launch
  @app.ping! unless ::Sidekiq.server?

  @app
end