Sha256: e618c5559654fa8423c0a6babe28b7cb2bcbb4a4d76c8cf587b355cb8893eb24

Contents?: true

Size: 866 Bytes

Versions: 13

Compression:

Stored size: 866 Bytes

Contents

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

module WorkerKiller
  class Middleware

    attr_reader :limiter, :killer, :reaction

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

      @reaction = reaction || proc do |l, k|
        k.kill(l.started_at)
      end

      @limiter = klass.new(**opts)
    end

    def call(env)
      @app.call(env)
    ensure
      reaction.call(limiter, killer) if limiter.check
    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

13 entries across 13 versions & 1 rubygems

Version Path
worker_killer-1.1.0.223443 lib/worker_killer/middleware.rb
worker_killer-1.1.0.214159 lib/worker_killer/middleware.rb
worker_killer-1.1.0.214146 lib/worker_killer/middleware.rb
worker_killer-1.0.5.213977 lib/worker_killer/middleware.rb
worker_killer-1.0.5.213889 lib/worker_killer/middleware.rb
worker_killer-1.0.4.189871 lib/worker_killer/middleware.rb
worker_killer-1.0.3.189564 lib/worker_killer/middleware.rb
worker_killer-1.0.3.189098 lib/worker_killer/middleware.rb
worker_killer-1.0.2.187852 lib/worker_killer/middleware.rb
worker_killer-1.0.2.187805 lib/worker_killer/middleware.rb
worker_killer-1.0.2.187732 lib/worker_killer/middleware.rb
worker_killer-1.0.1.83603 lib/worker_killer/middleware.rb
worker_killer-1.0.1.75538 lib/worker_killer/middleware.rb