PhoenixKit.Modules.Emails.BrevoOnDemandSync (phoenix_kit_emails v0.1.17)

Copy Markdown View Source

On-demand, targeted Brevo event fetch for a single email log — the Brevo-aware branch of the "sync status now" button (Details page and the emails list row menu both call it). Unlike BrevoPollingJob's broad polling cycle, this queries Brevo's events API filtered to exactly one messageId — the cheapest, most precise request the API supports.

A manual, explicit user request: bypasses brevo_events_enabled (the background poller can be off entirely and this still works) and the per-integration opt-out list (excluding an account from the background poll doesn't mean "never fetch its data even when asked directly"). Does NOT bypass Emails.enabled?/0 — the whole email system being off is a stronger signal than either of those.

There's no per-log integration reference to resolve credentials from (a Log doesn't record which SendProfile/integration sent it), so this tries every currently active Brevo integration — same set BrevoPollingJob polls — and aggregates whatever comes back. In the common single-account case that's one request; messageId is selective enough that a wrong account simply returns no events, not wrong data.

Summary

Functions

Fetches and processes events for a single Brevo-sent log right now.

Functions

sync(log)

@spec sync(PhoenixKit.Modules.Emails.Log.t()) ::
  {:ok, %{events_processed: non_neg_integer()}} | {:error, String.t()}

Fetches and processes events for a single Brevo-sent log right now.

Returns

  • {:ok, %{events_processed: n}}n may be 0 ("no new events")
  • {:error, reason} — a user-facing string, never includes credentials