Module: PGMQ::Client::Maintenance

Included in:
PGMQ::Client
Defined in:
lib/pgmq/client/maintenance.rb

Overview

Queue maintenance operations

This module handles queue maintenance tasks such as purging messages and detaching archive tables.

Instance Method Summary collapse

Instance Method Details

#disable_notify_insert(queue_name) ⇒ void

This method returns an undefined value.

Disables PostgreSQL NOTIFY for a queue

Examples:

client.disable_notify_insert("orders")

Parameters:

  • queue_name (String)

    name of the queue



66
67
68
69
70
71
72
73
74
# File 'lib/pgmq/client/maintenance.rb', line 66

def disable_notify_insert(queue_name)
  validate_queue_name!(queue_name)

  with_connection do |conn|
    conn.exec_params("SELECT pgmq.disable_notify_insert($1::text)", [queue_name])
  end

  nil
end

#enable_notify_insert(queue_name, throttle_interval_ms: 250) ⇒ void

This method returns an undefined value.

Enables PostgreSQL NOTIFY when messages are inserted into a queue

When enabled, PostgreSQL will send a NOTIFY event on message insert, allowing clients to use LISTEN instead of polling. The throttle interval prevents notification storms during high-volume inserts.

Examples:

Enable with default throttle (250ms)

client.enable_notify_insert("orders")

Enable with custom throttle (1 second)

client.enable_notify_insert("orders", throttle_interval_ms: 1000)

Disable throttling (notify on every insert)

client.enable_notify_insert("orders", throttle_interval_ms: 0)

Parameters:

  • queue_name (String)

    name of the queue

  • throttle_interval_ms (Integer) (defaults to: 250)

    minimum ms between notifications (default: 250)



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/pgmq/client/maintenance.rb', line 46

def enable_notify_insert(queue_name, throttle_interval_ms: 250)
  validate_queue_name!(queue_name)

  with_connection do |conn|
    conn.exec_params(
      "SELECT pgmq.enable_notify_insert($1::text, $2::integer)",
      [queue_name, throttle_interval_ms]
    )
  end

  nil
end

#purge_queue(queue_name) ⇒ Integer

Purges all messages from a queue

Examples:

count = client.purge_queue("old_queue")
puts "Purged #{count} messages"

Parameters:

  • queue_name (String)

    name of the queue

Returns:

  • (Integer)

    number of messages purged



18
19
20
21
22
23
24
25
26
# File 'lib/pgmq/client/maintenance.rb', line 18

def purge_queue(queue_name)
  validate_queue_name!(queue_name)

  result = with_connection do |conn|
    conn.exec_params("SELECT pgmq.purge_queue($1::text)", [queue_name])
  end

  result[0]["purge_queue"]
end