Skip to main content

Notifier

Struct Notifier 

Source
pub struct Notifier { /* private fields */ }
Expand description

The handle other modules call.

A venture gets one from crate::Notifications::notifier and hands it to its own modules; it is a cheap clone and shares the mounted module’s ports, so it is usable only after Harness::router has built the module’s router.

Implementations§

Source§

impl Notifier

Source

pub fn context(&self) -> Option<&Arc<ModuleContext>>

The mounted context, once Harness::router has built the module’s router. None before that.

Source

pub async fn notify( &self, db: &dyn Database, account_id: &str, category: &str, message: impl Into<Message>, ) -> Result<Enqueued, NotifyError>

Prepares one notification for every device account_id has.

Writes nothing: append Enqueued::statements to your own db.batch_atomic(..) so the notification is durable exactly when your state change is, then call Notifier::deliver_now.

message is either a Notification the caller wrote — today’s path, unchanged, and the one a single-language venture uses — or a Localizable naming a message in the venture’s catalog, which the drain renders per recipient (#190).

§Errors

NotifyError::UnknownCategory for a category the venture did not declare, NotifyError::InvalidData for a non-object data, NotifyError::NoCatalog for a localizable message in a venture with no catalog, and NotifyError::Database when a read fails.

Source

pub async fn notify_now( &self, db: &dyn Database, scope: &Scope, account_id: &str, category: &str, message: impl Into<Message>, ) -> Result<Enqueued, NotifyError>

Notifier::notify for a caller with no state change of its own: commits the outbox rows in their own batch and attempts immediate delivery. The event-bus entry point is this.

§Errors

As Notifier::notify, plus NotifyError::Database when the batch fails.

Source

pub async fn announce(&self, scope: &Scope, enqueued: &Enqueued)

Announces a just-committed inbox row to the account’s room, when the venture wired Realtime.

Call it after your batch commits, for the same reason Notifier::deliver_now says so: a client that received the event will read the inbox, and the row has to be there. Notifier::notify_now does it for you.

Deliberately not part of the drain. The drain runs only when there are push rows, and the account this matters most to — no device, or push refused — has none. A failure is logged and swallowed: a live update is an optimisation over the client’s own polling, and losing one must never fail the caller’s write. Announces a just-committed inbox row, and says on the bus that the catalog could not render part of the message (#190).

The two are here together because this is the first point in the batch API at which there is a Scope to emit an event in: Notifier::notify runs inside somebody else’s transaction and has none. A caller that batches its own statements and never calls this still learns about a missing translation from the drain, which reports one per delivery — but an account with no device and no mailbox has no delivery, so call it.

Source

pub fn deliver_now(&self, scope: &Scope)

Attempts immediate delivery on the request’s Defer.

Call it after your batch commits. Nothing is lost if the isolate dies first: the venture’s scheduled drain picks the rows up on the next tick.

Source

pub async fn drain(&self, scope: &Scope) -> Result<DrainReport, NotifyError>

Delivers every due outbox row this drainer can lease, through the mounted module’s ports.

The whole delivery policy lives here: Delivered completes the row, Unregistered deletes the row and the subscription, Rejected and NotConfigured dead-letter it, and Transient retries with backoff — never before the retry_after the provider asked for — to a bound, then dead-letters.

§Errors

NotifyError when the module is not mounted, a port is missing, or the claim itself fails. A per-row failure never aborts the pass: it is counted in DrainReport::failed and the row keeps its lease until it expires.

Source

pub async fn drain_with( &self, ctx: &ModuleContext, scope: &Scope, ) -> Result<DrainReport, NotifyError>

Notifier::drain through the ports of the context handed in.

This is what scheduled work must use. A cron invocation builds no router, so on a cold isolate there is no mounted context to drain through at all, and on a warm one draining through the parked context means using some earlier request’s database handle.

§Errors

As Notifier::drain, minus NotifyError::NotMounted: this entry point needs no mounted module.

Trait Implementations§

Source§

impl Clone for Notifier

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Notifier

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more