pub struct SystemClock;Expand description
The host’s system clock: what a table reads unless it names another.
§Examples
use std::time::{Duration, SystemTime};
use chrono::{DateTime, Utc};
use ruststream_sqlx::prelude::*;
use ruststream_sqlx::{Clock, SystemClock};
use serde::Deserialize;
use sqlx::PgPool;
/// The system clock five seconds ahead: a staging host replaying tomorrow's tasks a little early.
pub struct Ahead;
impl Clock for Ahead {
fn now() -> SystemTime {
SystemClock::now() + Duration::from_secs(5)
}
}
#[derive(Inbox, sqlx::FromRow)]
#[inbox(table = "replay_jobs", clock = Ahead)]
pub struct Replay {
#[field(id, generated)]
id: i64,
#[field(retry_after, generated)]
retry_after: DateTime<Utc>,
#[field(payload)]
payload: Vec<u8>,
}
#[derive(Deserialize)]
struct Task {
n: u32,
}
#[subscriber(InboxQueue::<Replay>::new("replays"))]
async fn replay(task: &Task) -> HandlerOutcome {
tracing::info!(task.n, "replaying");
HandlerOutcome::ack()
}
pub fn app(pool: PgPool) -> RustStream {
RustStream::new(AppInfo::new("staging", "0.1.0")).with_broker(SqlxBroker::new(pool), |b| {
b.include(replay);
})
}Trait Implementations§
Source§impl Clock for SystemClock
impl Clock for SystemClock
Source§fn now() -> SystemTime
fn now() -> SystemTime
Now.
Source§impl Clone for SystemClock
impl Clone for SystemClock
impl Copy for SystemClock
Source§impl Debug for SystemClock
impl Debug for SystemClock
Source§impl Default for SystemClock
impl Default for SystemClock
impl Eq for SystemClock
Source§impl Hash for SystemClock
impl Hash for SystemClock
Source§impl PartialEq for SystemClock
impl PartialEq for SystemClock
impl StructuralPartialEq for SystemClock
Auto Trait Implementations§
impl Freeze for SystemClock
impl RefUnwindSafe for SystemClock
impl Send for SystemClock
impl Sync for SystemClock
impl Unpin for SystemClock
impl UnsafeUnpin for SystemClock
impl UnwindSafe for SystemClock
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more