Class: GitLab::Exporter::WebExporter::MemoryKillerMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab_exporter/web_exporter.rb

Overview

A middleware to kill the process if we exceeded a certain threshold

Instance Method Summary collapse

Constructor Details

#initialize(app, memory_threshold) ⇒ MemoryKillerMiddleware

Returns a new instance of MemoryKillerMiddleware.



14
15
16
17
# File 'lib/gitlab_exporter/web_exporter.rb', line 14

def initialize(app, memory_threshold)
  @app = app
  @memory_threshold = memory_threshold.to_i * 1024
end

Instance Method Details

#call(env) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/gitlab_exporter/web_exporter.rb', line 19

def call(env)
  if memory_usage > @memory_threshold
    puts "Memory usage of #{memory_usage} exceeded threshold of #{@memory_threshold}, signalling KILL"
    Process.kill("KILL", $PID)
  end

  @app.call(env)
end