Jido.Messaging.Deduper (Jido Messaging v1.0.0)

Copy Markdown View Source

Central message deduplication using ETS with TTL.

Prevents duplicate processing of inbound messages by tracking seen message keys. Keys expire after a configurable TTL and are periodically swept.

Usage

# Check and mark atomically (returns :new or :duplicate)
case Deduper.check_and_mark(MyApp.Messaging, {:telegram, "inst_123", 12345}) do
  :new -> process_message()
  :duplicate -> :ok
end

Summary

Functions

Check if a key has been seen before and mark it as seen if new.

Returns a specification to start this module under a supervisor.

Clear all dedupe keys (useful for testing).

Get the count of tracked keys.

Returns the Zoi schema

Check if a key has been seen (without marking).

Types

key()

@type key() :: term()

t()

@type t() :: %Jido.Messaging.Deduper{
  instance_module: any(),
  table: any(),
  ttl_ms: integer()
}

Functions

check_and_mark(messaging_module, key, ttl_ms \\ nil)

@spec check_and_mark(module(), key(), non_neg_integer() | nil) :: :new | :duplicate

Check if a key has been seen before and mark it as seen if new.

Returns :new if the key is new (and marks it), :duplicate if already seen.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

clear(messaging_module)

@spec clear(module()) :: :ok

Clear all dedupe keys (useful for testing).

count(messaging_module)

@spec count(module()) :: non_neg_integer()

Get the count of tracked keys.

mark_seen(messaging_module, key, ttl_ms \\ nil)

@spec mark_seen(module(), key(), non_neg_integer() | nil) :: :ok

Manually mark a key as seen.

schema()

Returns the Zoi schema

seen?(messaging_module, key)

@spec seen?(module(), key()) :: boolean()

Check if a key has been seen (without marking).

start_link(opts)