diff --git a/delayed_job.gemspec b/delayed_job.gemspec index b45c7d1cf..0299ae103 100644 --- a/delayed_job.gemspec +++ b/delayed_job.gemspec @@ -2,6 +2,7 @@ Gem::Specification.new do |spec| spec.add_dependency 'activesupport', ['>= 3.0', '< 6.1'] + spec.add_dependency 'get_process_mem' spec.authors = ['Brandon Keepers', 'Brian Ryckbost', 'Chris Gaffney', 'David Genord II', 'Erik Michaels-Ober', 'Matt Griffin', 'Steve Richert', 'Tobias Lütke'] spec.description = 'Delayed_job (or DJ) encapsulates the common pattern of asynchronously executing longer tasks in the background. It is a direct extraction from Shopify where the job table is responsible for a multitude of core tasks.' spec.email = ['brian@collectiveidea.com'] diff --git a/lib/delayed/worker.rb b/lib/delayed/worker.rb index 1a352f775..bb36aea38 100644 --- a/lib/delayed/worker.rb +++ b/lib/delayed/worker.rb @@ -6,6 +6,7 @@ require 'active_support/core_ext/hash/indifferent_access' require 'logger' require 'benchmark' +require 'get_process_mem' module Delayed class Worker # rubocop:disable ClassLength @@ -225,12 +226,14 @@ def work_off(num = 100) end def run(job) - job_say job, 'RUNNING' + mem_monitor = GetProcessMem.new + start_mem = mem_monitor.mb + job_say job, format('RUNNING, mem %.1f Mb', mem: start_mem) runtime = Benchmark.realtime do Timeout.timeout(max_run_time(job).to_i, WorkerTimeout) { job.invoke_job } job.destroy end - job_say job, format('COMPLETED after %.4f', runtime) + job_say job, format('COMPLETED after %.4f, mem leak %.1f Mb', runtime: runtime, memleak: mem_monitor.mb - start_mem) return true # did work rescue DeserializationError => error job_say job, "FAILED permanently with #{error.class.name}: #{error.message}", 'error'