Sha256: 05d2a9fa953c3b4a6ae3f660e5de4db69b6e3c017e3bdd47665d97dc67811574

Contents?: true

Size: 835 Bytes

Versions: 6

Compression:

Stored size: 835 Bytes

Contents

require 'worker_killer/memory_limiter'
require 'worker_killer/count_limiter'

module WorkerKiller
  class Middleware

    attr_reader :limiter

    def initialize(app, klass:, reaction: nil, **opts)
      @app = app

      reaction ||= proc do |limiter|
        WorkerKiller.kill_self(limiter.logger, limiter.started_at)
      end

      @limiter = klass.new(opts, &reaction)
    end

    def call(env)
      response = @app.call(env)
      @limiter.check
      response
    end

    class RequestsLimiter < ::WorkerKiller::Middleware

      def initialize(app, **opts)
        super(app, klass: ::WorkerKiller::CountLimiter, **opts)
      end

    end

    class OOMLimiter < ::WorkerKiller::Middleware

      def initialize(app, **opts)
        super(app, klass: ::WorkerKiller::MemoryLimiter, **opts)
      end

    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
worker_killer-0.1.0.19844 lib/worker_killer/middleware.rb
worker_killer-0.1.0.19842 lib/worker_killer/middleware.rb
worker_killer-0.1.0.19841 lib/worker_killer/middleware.rb
worker_killer-0.1.0.19840 lib/worker_killer/middleware.rb
worker_killer-0.1.0.19839 lib/worker_killer/middleware.rb
worker_killer-0.0.9.19836 lib/worker_killer/middleware.rb