Scrypath.Oban (scrypath v0.3.21)

Copy Markdown View Source

Narrow Oban helpers for composing Scrypath sync jobs into Ecto.Multi.

enqueue_upsert/5 and enqueue_delete/5 add one job per Ecto.Multi step, whatever the number of records or ids. Unlike Scrypath.sync_records/3 under sync_mode: :oban, they do not split the ids into several jobs; the worker bounds each backend write to at most 1000 documents or ids.

These helpers insert the job inside your transaction, and they insert it without the shared unique: policy: the job only becomes visible when your transaction commits, so it always reads committed rows and never collapses into a pending job that could run before your commit. The cost is that an identical pending job may run twice, which is harmless because upserts and deletes are keyed by id.

Summary

Functions

enqueue_delete(multi, name, schema_module, document_ids, opts)

@spec enqueue_delete(Ecto.Multi.t(), Ecto.Multi.name(), module(), [term()], keyword()) ::
  Ecto.Multi.t()

enqueue_upsert(multi, name, schema_module, records, opts)

@spec enqueue_upsert(
  Ecto.Multi.t(),
  Ecto.Multi.name(),
  module(),
  [struct() | map()],
  keyword()
) ::
  Ecto.Multi.t()