Sha256: 37f14ecd47b5c8c2adf70f41afb7de9fcc97d6c1c98034b12335d7fec5a36b03

Contents?: true

Size: 1.14 KB

Versions: 13

Compression:

Stored size: 1.14 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
        GoodJob::Process.override_connection(connection) do
          GoodJob::Process.cleanup
          @capsule.tracker.register(with_advisory_lock: true)
        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: true)
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
good_job-4.1.1 lib/good_job/notifier/process_heartbeat.rb
good_job-4.1.0 lib/good_job/notifier/process_heartbeat.rb
good_job-3.99.1 lib/good_job/notifier/process_heartbeat.rb
good_job-4.0.3 lib/good_job/notifier/process_heartbeat.rb
good_job-4.0.2 lib/good_job/notifier/process_heartbeat.rb
good_job-4.0.1 lib/good_job/notifier/process_heartbeat.rb
good_job-4.0.0 lib/good_job/notifier/process_heartbeat.rb
good_job-3.99.0 lib/good_job/notifier/process_heartbeat.rb
good_job-3.30.1 lib/good_job/notifier/process_heartbeat.rb
good_job-3.30.0 lib/good_job/notifier/process_heartbeat.rb
good_job-3.29.5 lib/good_job/notifier/process_heartbeat.rb
good_job-3.29.4 lib/good_job/notifier/process_heartbeat.rb
good_job-3.29.3 lib/good_job/notifier/process_heartbeat.rb