Configure Node Recovery for unexpected shutdowns
masterExq provides two mechanisms to recover jobs left in an 'in-progress' state after a node crash:
1. Same Node Recovery
Exq uses a node_identifier to track jobs. By default, this is the machine's hostname. If a node restarts with the same identifier, it re-enqueues its in-progress jobs. In environments like Kubernetes where hostnames change, implement a custom Exq.NodeIdentifier.Behaviour.
2. Heartbeat Mechanism
If a node is gone for a long time (e.g., autoscaling), the heartbeat mechanism detects it. If a node misses missed_heartbeats_allowed consecutive heartbeats, its in-progress jobs are re-enqueued. This is disabled by default.
Configuration:
config :exq,
heartbeat_enable: true,
heartbeat_interval: 60_000,
missed_heartbeats_allowed: 5# Custom Node Identifier implementation
defmodule MyApp.CustomNodeIdentifier do
@behaviour Exq.NodeIdentifier.Behaviour
def node_id do
System.get_env("NODE_ID")
end
end
# In config.exs
config :exq,
node_identifier: MyApp.CustomNodeIdentifier