mod autonomous;
mod changes;
mod channel;
mod downstream;
mod engine;
mod fate;
mod feed;
mod generations;
mod intake;
mod invoke;
mod journal;
mod lane;
mod launch;
mod lifecycle;
mod message;
mod notify;
mod observe;
mod pair;
mod policy;
mod poll;
mod progress;
mod registry;
mod resident;
mod retired;
mod serve;
mod stream;
mod tick;
mod window;
pub use autonomous::{Helm, Runs, Upstreams};
pub use changes::{
AsyncChanges, ChangeIntake, Doorbell, Hint, IntakeError, Page, Pulled, Rung, doorbell,
};
#[cfg(feature = "sqlite")]
pub use changes::{SqliteFeed, SqliteFeedError};
pub use channel::{ChannelOptions, Evictor, Inbox, Nudge, Outbox, Wake, channel, open};
pub use downstream::{Attached, Attaches, Downstream, Sink, Socket, Wanted};
pub use engine::{AfterClock, Unruntimed};
pub use fate::{Fate, Terminal};
#[cfg(target_os = "macos")]
pub use feed::Darwin;
pub use feed::{
DEFAULT_FEED_DEPTH, FeedContext, FeedPolicy, Fixed, MemoryAware, MemoryProbe, Pressure, Steady,
Unpressured,
};
pub use generations::{
CURRENT_TABLE_PREFIX, Culled, Curator, CuratorBody, CuratorReport, CurrentRow, CurrentTable,
DEFAULT_KEEP, Generational, GenerationsEngine, GenerationsOptions, GenerationsOverride,
GenerationsStore, GenerationsStoreError, RUN_COLUMN, RunId, Scope, Turning,
UnknownGenerationsEngine, UnnameableScope, UnnameableTable, prepare,
};
#[cfg(any(feature = "sqlite", feature = "postgres", feature = "mysql"))]
pub use generations::{GenerationsSql, SqlGenerations, current_filter};
pub use intake::{Arm, Intake, arm, park_on, select};
pub use invoke::{
Answers, AsyncAnswers, Awaiting, Door, Invoke, Invokes, Onward, QueryArm, QueryError, Reply,
Served, door, reply,
};
pub use journal::{
Attributes, JournalDrain, JournalQueue, JournalRow, JournalTap, JournalWriter, Ledger, Written,
journal_queue,
};
pub use lane::{AsyncLands, Commit, Lands, Unwritten};
pub(crate) use lane::block_until;
pub use launch::{
App, ArrangementError, Assembly, AsyncConstructor, AsyncInitialize, AsyncTeardown, Autonomous,
AutonomousBody, BareOptions, Blueprint, BoxedError, Bridged, Buffered, Cell, ChannelShelf,
Channels, Context, Creation, Declared, DeclaredResident, Died, DisabledUpstreamError,
DroppingUnboundedError, EdgeTypeError, Enablement, Enrolled, FeederAbsentError, Goodbye, Grant,
GrantsNoStoreError, Habitats, Ignition, Initialize, Initializes, LandsNowhereError, LaneMount,
LaunchError, Lived, MakesNothing, MandatoryOptionsError, MandatoryResourceOptionsError,
MissingResourceError, Mount, MountBody, Mounted, MountedLane, NoDefaultOptions, NodeAttribution,
NodeBody, NodeSection, NodeWiring, Ordered, Party, Plan, PolicyShelf, Posted, Produced,
ProductSeatError, PureLeafError, Refusal, ResourceSourceError, Resources, Shutdown, SlotBinding,
SplitOriginError, Staging, Stopped, StreamBody, StreamWires, Streaming, TakenInboxError, Tuned,
UnboundCorpus, UnboundSlotError, UnbridgedOriginError, UnbuiltTargetError,
UncataloguedResourceError, Unchanneled, UndeclaredResourceError, UnknownGrantError,
UnknownNodeError, UnknownUpstreamError, Unpoliced, Untorn, Upstream, UpstreamWiring, Wired,
Wiring, Worn, bare_options, bare_origin_options, bare_resource_options, drive_awaited_origin,
drive_origin,
};
pub use lifecycle::{
Arrival, Failure, Lifecycle, LifecycleTap, Observation, RecordingTap, Station, Taps,
};
pub use message::{
Ack, AckReceiver, AckSender, Answer, Custody, Delivery, Item, Owing, Payload, PayloadIter,
ReceiptMap, Settled, SettledParts, Share, Unreceipted, Unsettled, ack_channel,
};
pub use notify::Notified;
pub use observe::TracingLevel;
#[cfg(feature = "tracing")]
pub use observe::TracingTap;
pub use pair::{Group, Joins, Pairing};
pub use policy::{
Backpressure, CatchUp, Coalesce, Concern, DeadlinePolicy, Deadlines, DropNewest, DropOldest,
Handover, Missed, NoDeadline, NoRetry, Occupancy, OverflowDecision, OverflowPolicy, Policies,
QueryDeadline, Retries, RetryDecision, RetryPolicy, ShedKey, Sheds, TickDecision, TickPolicy,
Ticks,
};
pub use poll::{
Cadence, Calendar, CalendarError, PollUpstream, Recurrence, Schedule, Seats, Swept, Ticked,
Ticker, Unpolled,
};
pub use progress::{PositionKey, Positions, RecordedPositions, Track};
#[cfg(feature = "sqlite")]
pub use progress::{SqlitePositions, SqlitePositionsError};
pub use registry::{
DEFAULT_BATCH_MAX_ITEMS, DEFAULT_BATCH_MAX_WAIT, DEFAULT_DEBOUNCE, DEFAULT_RETIRE_DRAIN,
DEFAULT_SETTLE, DriverEngine, Flip, GenerationLedger, Registries, Registry, RegistryCounts,
RegistryDriver, RegistryOptions, RegistryOverride, RetireOrigin, RetiredLedger, Retirement,
RootAction, RootAdvance, RootKey, RootProjection, RootState, Stamp,
};
#[cfg(feature = "async-graphql")]
pub(crate) use registry::DynRegistry;
pub use resident::{Drained, Drives, Resident, Tally};
#[cfg(feature = "mongodb")]
pub use retired::MongoRetired;
pub use retired::{
Keeper, KeeperBody, KeeperReport, Landing, RETIRED_TABLE_PREFIX, RetiredEngine, RetiredMirror,
RetiredOptions, RetiredReader, RetiredReaders, RetiredRow, RetiredStore, RetiredStoreError,
RetiredTable, UnknownRetiredEngine, UnnameableFamily, rebuild,
};
#[cfg(any(feature = "sqlite", feature = "postgres", feature = "mysql"))]
pub use retired::{RetiredSql, SqlRetired};
pub use serve::{
AsyncServes, DefaultServe, Flow, FulltextAsk, FulltextScope, Responding, Serve, Serves, SlotLane,
VectorAsk, VectorScope,
};
pub use stream::{
DEFAULT_IN_FLIGHT, StreamLane, StreamOptions, Streamed, Streams, UNDIVIDABLE, Vanished,
};
#[cfg(feature = "rayon")]
pub use tick::Rayon;
pub use tick::{AsyncSpawn, AsyncTick, AtMostOne, InFlight, Spawn, Tasks, Thread, Tick};
pub use window::{Answered, Harvest, Lineage, Outbound, Owed};
use core::time::Duration;
use crate::name::borrowed_name;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, derive_more::Display)]
#[display("item#{_0}")]
pub struct ItemId(u64);
impl ItemId {
#[inline]
#[must_use]
pub const fn new(seq: u64) -> Self {
Self(seq)
}
#[inline]
#[must_use]
pub const fn seq(&self) -> u64 {
self.0
}
}
borrowed_name! {
pub struct NodeName;
}
impl NodeName {
#[inline]
#[must_use]
pub const fn new(name: &str) -> &Self {
Self::view(name)
}
#[inline]
#[must_use]
pub const fn as_str(&self) -> &str {
&self.0
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, derive_more::Display, derive_more::IsVariant)]
#[display("{}", self.as_str())]
pub enum Listen {
Channel,
Changes(Feeder),
Poll(Duration),
Transient,
}
impl Listen {
#[inline]
#[must_use]
pub const fn as_str(&self) -> &'static str {
match self {
Self::Channel => "channel",
Self::Changes(_) => "changes",
Self::Poll(_) => "poll",
Self::Transient => "transient",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, derive_more::Display, derive_more::IsVariant)]
#[display("{}", self.as_str())]
pub enum Feeder {
InGraph,
External,
}
impl Feeder {
#[inline]
#[must_use]
pub const fn as_str(&self) -> &'static str {
match self {
Self::InGraph => "in-graph",
Self::External => "external",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, derive_more::Display, derive_more::IsVariant)]
#[display("{}", self.as_str())]
pub enum AckMode {
Local,
Chained,
}
impl AckMode {
#[inline]
#[must_use]
pub const fn as_str(&self) -> &'static str {
match self {
Self::Local => "local",
Self::Chained => "chained",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, derive_more::Display, derive_more::IsVariant)]
#[display("{}", self.as_str())]
pub enum Effect {
Lands,
Pure,
}
impl Effect {
#[inline]
#[must_use]
pub const fn as_str(&self) -> &'static str {
match self {
Self::Lands => "lands",
Self::Pure => "pure",
}
}
#[inline]
pub(crate) fn reached<I>(self, info: I) -> Lifecycle<I> {
match self {
Self::Lands => Lifecycle::Persisted(info),
Self::Pure => Lifecycle::Processed(info),
}
}
#[inline]
pub(crate) const fn station(self) -> Station {
match self {
Self::Lands => Station::Persisted,
Self::Pure => Station::Processed,
}
}
}
pub trait Rings: Send {
fn ring(&self) -> bool;
}
#[derive(Debug)]
pub struct Sweeper {
stop: flume::Sender<()>,
thread: Option<std::thread::JoinHandle<()>>,
}
impl Sweeper {
#[must_use]
pub fn spawn(interval: Duration, ringers: Vec<Box<dyn Rings>>) -> Self {
Self::ticking(
ringers
.into_iter()
.map(|ringer| Cadence::new(interval, ringer))
.collect(),
)
}
#[must_use]
pub fn ticking(cadences: Vec<Cadence>) -> Self {
let (stop, halt) = flume::bounded(1);
let thread = std::thread::Builder::new()
.name("ingraph-sweep".to_owned())
.spawn(move || {
let now = std::time::Instant::now();
let mut due: Vec<Option<std::time::Instant>> = cadences
.iter()
.map(|cadence| cadence.until_next().map(|wait| now + wait))
.collect();
let mut live = vec![true; cadences.len()];
loop {
let now = std::time::Instant::now();
let Some(wait) = due
.iter()
.zip(&live)
.filter(|&(_, live)| *live)
.filter_map(|(due, _)| *due)
.map(|due| due.saturating_duration_since(now))
.min()
else {
return;
};
if halt.recv_timeout(wait) != Err(flume::RecvTimeoutError::Timeout) {
return;
}
let now = std::time::Instant::now();
for (index, cadence) in cadences.iter().enumerate() {
if live[index] && due[index].is_some_and(|due| due <= now) {
due[index] = cadence.until_next().map(|wait| now + wait);
live[index] = cadence.ring();
}
}
}
})
.expect("the sweep thread");
Self {
stop,
thread: Some(thread),
}
}
}
impl Drop for Sweeper {
fn drop(&mut self) {
let _ = self.stop.send(());
if let Some(thread) = self.thread.take() {
let _ = thread.join();
}
}
}
#[cfg(test)]
mod tests;