Sha256: ceb0ea9975eb72806c84c2003a28b0064397fe80cdd4ed2a5429c8dbd099c32b

Contents?: true

Size: 1.26 KB

Versions: 11

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

module GoodJob # :nodoc:
  class Notifier # :nodoc:
    # Extends the Notifier to register the process in the database.
    module ProcessHeartbeat
      extend ActiveSupport::Concern

      included do
        set_callback :listen, :after, :register_process
        set_callback :tick, :before, :refresh_process
        set_callback :unlisten, :after, :deregister_process
      end

      # Registers the current process.
      def register_process
        @advisory_lock_heartbeat = GoodJob.configuration.advisory_lock_heartbeat
        GoodJob::Process.override_connection(connection) do
          GoodJob::Process.cleanup
          @capsule.tracker.register(with_advisory_lock: @advisory_lock_heartbeat)
        end
      end

      def refresh_process
        Rails.application.executor.wrap do
          GoodJob::Process.override_connection(connection) do
            GoodJob::Process.with_logger_silenced do
              @capsule.tracker.renew
            end
          end
        end
      end

      # Deregisters the current process.
      def deregister_process
        GoodJob::Process.override_connection(connection) do
          @capsule.tracker.unregister(with_advisory_lock: @advisory_lock_heartbeat)
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
good_job-4.8.0 lib/good_job/notifier/process_heartbeat.rb
good_job-4.7.0 lib/good_job/notifier/process_heartbeat.rb
good_job-4.6.0 lib/good_job/notifier/process_heartbeat.rb
good_job-4.5.1 lib/good_job/notifier/process_heartbeat.rb
good_job-4.5.0 lib/good_job/notifier/process_heartbeat.rb
good_job-4.4.2 lib/good_job/notifier/process_heartbeat.rb
good_job-4.4.1 lib/good_job/notifier/process_heartbeat.rb
good_job-4.4.0 lib/good_job/notifier/process_heartbeat.rb
good_job-4.3.0 lib/good_job/notifier/process_heartbeat.rb
good_job-4.2.1 lib/good_job/notifier/process_heartbeat.rb
good_job-4.2.0 lib/good_job/notifier/process_heartbeat.rb