mule/plugins/reindexer

The Reindexer plugin: rebuild the job-table indexes on a cron schedule, to reclaim the bloat that heavy insert/delete churn leaves behind. A Stager-shaped actor — the REINDEX (and the drop of any INVALID mule_jobs* leftovers from failed concurrent builds) lives in the engine (engine.reindex, per driver); this plugin evaluates its schedule once per minute and drives the engine when it matches. A no-op on engines with no indexes (in-memory). Mirrors Oban.Plugins.Reindexer.

Leader-only, so the rebuild runs once cluster-wide: the leader check reads config.peer.is_leader() (a pure cell lookup) — the Postgres lease peer elects one node, and single-node / in-memory uses peer.always_leader. The Postgres engine rebuilds CONCURRENTLY, so producers keep fetching while it runs; the default schedule is @midnight, since index bloat builds up slowly.

Types

pub type Message {
  Reindex
}

Constructors

  • Reindex

The reindexer’s options (reindexer.ex :schedule / :indexes / :timeout / :timezone), folded over the defaults: @midnight, the two GIN indexes (mule_jobs_args_index, mule_jobs_meta_index), 15 seconds, Etc/UTC.

pub type Option {
  Schedule(schedule: String)
  Indexes(indexes: List(String))
  Timeout(timeout: duration.Duration)
  Timezone(timezone: String)
}

Constructors

  • Schedule(schedule: String)

    A cron expression controlling when to reindex.

  • Indexes(indexes: List(String))

    The mule_jobs indexes to rebuild.

  • Timeout(timeout: duration.Duration)

    Per-statement query timeout.

  • Timezone(timezone: String)

    The IANA timezone the schedule evaluates in; a non-UTC zone resolves through the OS timezone database, and an unknown name fails the start.

pub type State {
  State(
    config: config.Config,
    schedule: expression.Expression,
    indexes: List(String),
    timeout_milliseconds: Int,
    local_clock: cron.LocalClock,
    clock: fn() -> timestamp.Timestamp,
    self_subject: process.Subject(Message),
  )
}

Constructors

Values

pub fn plugin() -> plugin.Plugin

Package the Reindexer with its defaults (rebuild the two GIN indexes at midnight UTC) as a runtime Plugin for MuleSpec.plugins.

pub fn plugin_with(
  options options: List(Option),
) -> plugin.Plugin

plugin with options.

pub fn start(
  config config: config.Config,
  options options: List(Option),
) -> Result(
  actor.Started(process.Subject(Message)),
  actor.StartError,
)
pub fn start_with_clock(
  config config: config.Config,
  options options: List(Option),
  clock clock: fn() -> timestamp.Timestamp,
) -> Result(
  actor.Started(process.Subject(Message)),
  actor.StartError,
)

Start with an injected clock — used by tests to drive evaluation at a chosen instant rather than waiting for a real minute boundary.

Search Document