Sha256: 70bc79a9689f962b4dbf1b45d8a1e33790ba5c4a3af00c2fbbd874ee35ee8c7d

Contents?: true

Size: 1.1 KB

Versions: 22

Compression:

Stored size: 1.1 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.with_connection(connection) do
          GoodJob::Process.cleanup
          @process = GoodJob::Process.register
        end
      end

      def refresh_process
        Rails.application.executor.wrap do
          GoodJob::Process.with_connection(connection) do
            GoodJob::Process.with_logger_silenced do
              @process&.refresh_if_stale(cleanup: true)
            end
          end
        end
      end

      # Deregisters the current process.
      def deregister_process
        GoodJob::Process.with_connection(connection) do
          @process&.deregister
        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
good_job-3.24.0 lib/good_job/notifier/process_heartbeat.rb
good_job-3.23.0 lib/good_job/notifier/process_heartbeat.rb
good_job-3.22.0 lib/good_job/notifier/process_heartbeat.rb
good_job-3.21.5 lib/good_job/notifier/process_heartbeat.rb
good_job-3.21.4 lib/good_job/notifier/process_heartbeat.rb
good_job-3.21.3 lib/good_job/notifier/process_heartbeat.rb
good_job-3.21.2 lib/good_job/notifier/process_heartbeat.rb
good_job-3.21.1 lib/good_job/notifier/process_heartbeat.rb
good_job-3.21.0 lib/good_job/notifier/process_heartbeat.rb
good_job-3.20.0 lib/good_job/notifier/process_heartbeat.rb
good_job-3.19.4 lib/good_job/notifier/process_heartbeat.rb
good_job-3.19.3 lib/good_job/notifier/process_heartbeat.rb
good_job-3.19.2 lib/good_job/notifier/process_heartbeat.rb
good_job-3.19.1 lib/good_job/notifier/process_heartbeat.rb
good_job-3.19.0 lib/good_job/notifier/process_heartbeat.rb
good_job-3.18.3 lib/good_job/notifier/process_heartbeat.rb
good_job-3.18.2 lib/good_job/notifier/process_heartbeat.rb
good_job-3.18.1 lib/good_job/notifier/process_heartbeat.rb
good_job-3.18.0 lib/good_job/notifier/process_heartbeat.rb
good_job-3.17.4 lib/good_job/notifier/process_heartbeat.rb