Sha256: 9bc82cf47cd319df6d7c116543b6d17cdca9fd52c5496de3a564779b8d35c2de

Contents?: true

Size: 971 Bytes

Versions: 16

Compression:

Stored size: 971 Bytes

Contents

require 'delayed_job'

#
# Updates the modification time of the file $RAILS_ROOT/tmp/delayed_job_activity when
# relevant worker activity occurs. To be used for monitoring whether a DelayedJob
# worker is still picking up new work in a timely fashion.
#
# A file based approach is used so it is easy to add a health check to a Docker container
# with the following command:
# `find /app/tmp -mmin -$MAXIMUM_AGE_OF_FILE_IN_MINUTES -type f -print | grep delayed_job_activity`
#
module DelayedJobActivityMonitoring
  def work_off(num = 100)
    FileUtils.touch(Rails.root.join('tmp', 'delayed_job_activity'))
    super(num)
  end

  protected

  def reserve_job
    super.tap do |job|
      if job
        FileUtils.touch(
          Rails.root.join('tmp', 'delayed_job_activity'),
          mtime: job.max_run_time.from_now
        )
      end
    end
  end
end

Delayed::Worker.send(:prepend, DelayedJobActivityMonitoring) if defined?(Delayed) && defined?(Delayed::Worker)

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
roqua-support-0.4.6 lib/roqua/core_ext/delayed_job/activity_monitoring.rb
roqua-support-0.4.5 lib/roqua/core_ext/delayed_job/activity_monitoring.rb
roqua-support-0.4.4 lib/roqua/core_ext/delayed_job/activity_monitoring.rb
roqua-support-0.4.3 lib/roqua/core_ext/delayed_job/activity_monitoring.rb
roqua-support-0.4.2 lib/roqua/core_ext/delayed_job/activity_monitoring.rb
roqua-support-0.4.1 lib/roqua/core_ext/delayed_job/activity_monitoring.rb
roqua-support-0.4.0 lib/roqua/core_ext/delayed_job/activity_monitoring.rb
roqua-support-0.3.5 lib/roqua/core_ext/delayed_job/activity_monitoring.rb
roqua-support-0.3.4 lib/roqua/core_ext/delayed_job/activity_monitoring.rb
roqua-support-0.3.3 lib/roqua/core_ext/delayed_job/activity_monitoring.rb
roqua-support-0.3.2 lib/roqua/core_ext/delayed_job/activity_monitoring.rb
roqua-support-0.3.1 lib/roqua/core_ext/delayed_job/activity_monitoring.rb
roqua-support-0.3.0 lib/roqua/core_ext/delayed_job/activity_monitoring.rb
roqua-support-0.1.34 lib/roqua/core_ext/delayed_job/activity_monitoring.rb
roqua-support-0.1.33 lib/roqua/core_ext/delayed_job/activity_monitoring.rb
roqua-support-0.1.32 lib/roqua/core_ext/delayed_job/activity_monitoring.rb