Skip to content

Commit

Permalink
log memory consumption
Browse files Browse the repository at this point in the history
  • Loading branch information
xronos-i-am committed Oct 16, 2020
1 parent 8c52ad2 commit 7f21830
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions delayed_job.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ['[email protected]']
Expand Down
7 changes: 5 additions & 2 deletions lib/delayed/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 %<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 %<runtime>.4f, mem leak %<memleak>.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'
Expand Down

0 comments on commit 7f21830

Please sign in to comment.