Module: RocketJob::Server::Model

Extended by:
ActiveSupport::Concern
Included in:
RocketJob::Server
Defined in:
lib/rocket_job/server/model.rb

Overview

Model attributes

Instance Method Summary collapse

Instance Method Details

#refresh(worker_count) ⇒ Object

Updates the heartbeat and returns a refreshed server instance.



110
111
112
113
114
115
116
117
# File 'lib/rocket_job/server/model.rb', line 110

def refresh(worker_count)
  SemanticLogger.silence(:info) do
    find_and_update(
      "heartbeat.updated_at" => Time.now,
      "heartbeat.workers"    => worker_count
    )
  end
end

#zombie?(missed = 4) ⇒ Boolean

Returns [true|false] if this server has missed at least the last 4 heartbeats

Possible causes for a server to miss its heartbeats:

  • The server process has died

  • The server process is “hanging”

  • The server is no longer able to communicate with the MongoDB Server

Returns:

  • (Boolean)


101
102
103
104
105
106
107
# File 'lib/rocket_job/server/model.rb', line 101

def zombie?(missed = 4)
  return false unless running? || stopping? || paused?
  return true if heartbeat.nil? || heartbeat.updated_at.nil?

  dead_seconds = Config.heartbeat_seconds * missed
  (Time.now - heartbeat.updated_at) >= dead_seconds
end