Sha256: 47ef23b14be77962f770701af0cc32b337d4c861510d52784b2801a0632f7c73

Contents?: true

Size: 903 Bytes

Versions: 5

Compression:

Stored size: 903 Bytes

Contents

# frozen_string_literal: true

require 'get_process_mem'

module Delayed
  module Master
    class Worker
      module Plugins
        class MemoryChecker < Delayed::Plugin
          callbacks do |lifecycle|
            lifecycle.before(:perform) do |worker, job|
              mem = GetProcessMem.new
              worker.master_logger.info { "performing #{job.name}, memory: #{mem.mb.to_i} MB" }
            end
            lifecycle.after(:perform) do |worker, job|
              mem = GetProcessMem.new
              worker.master_logger.info { "performed #{job.name}, memory: #{mem.mb.to_i} MB" }
              if worker.max_memory && mem.mb > worker.max_memory
                worker.master_logger.info { "shutting down worker #{Process.pid} because it consumes large memory..." }
                worker.stop
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
delayed_job_master-3.1.2 lib/delayed/master/worker/plugins/memory_checker.rb
delayed_job_master-3.1.1 lib/delayed/master/worker/plugins/memory_checker.rb
delayed_job_master-3.1.0 lib/delayed/master/worker/plugins/memory_checker.rb
delayed_job_master-3.0.1 lib/delayed/master/worker/plugins/memory_checker.rb
delayed_job_master-3.0.0 lib/delayed/master/worker/plugins/memory_checker.rb