Skip to main content

BatchResolver

Struct BatchResolver 

Source
pub struct BatchResolver<R: Resolver> { /* private fields */ }
Expand description

The async batch resolver. Generic over any Resolver; the cache and queue backends are type-erased so the type does not carry them.

This example seeds the cache before draining, so Self::drain resolves "M31" from the cache alone — no network call, so it runs without crate::OfflineResolver ever reaching a resolver backend.

use simbad_resolver::{
    AliasKind, BatchResolver, Cache, ObjectType, OfflineResolver, ResolvedAlias,
    ResolvedIdentity, ResolverConfig, Store, TargetSource,
};

let store = Store::in_memory()?;
let config = ResolverConfig::new("guide.example");
let namespace = config.namespace;

let m31 = ResolvedIdentity {
    simbad_oid: Some(1_575_544),
    primary_designation: "M 31".to_owned(),
    common_name: None,
    object_type: ObjectType::Galaxy,
    otype_raw: "G".to_owned(),
    ra_deg: 10.684_708,
    dec_deg: 41.268_75,
    v_mag: Some(3.44),
    aliases: vec![ResolvedAlias::new("M 31", AliasKind::Designation)],
    source: TargetSource::Seed,
};
store.cache().upsert(&m31, &namespace).await?;

let batch = BatchResolver::new(OfflineResolver, store.cache(), store.queue(), config)
    .with_batch_size(8);
batch.enqueue("job-1", "M31").await?;

let summary = batch.drain().await?;
assert_eq!(summary.resolved, 1, "cache hit, no resolver call needed");

Implementations§

Source§

impl<R: Resolver> BatchResolver<R>

Source

pub fn new( resolver: R, cache: impl Cache + 'static, queue: impl Queue + 'static, config: ResolverConfig, ) -> Self

Construct a batch resolver from caller-supplied cache and queue backends — typically a Store’s .cache() and .queue() over one shared database.

use simbad_resolver::{BatchResolver, OfflineResolver, ResolverConfig, Store};

let store = Store::in_memory()?;
let batch =
    BatchResolver::new(OfflineResolver, store.cache(), store.queue(), ResolverConfig::new("x"));
Source

pub fn with_batch_size(self, n: usize) -> Self

Set how many pending items are claimed per round (min 1).

use simbad_resolver::{BatchResolver, OfflineResolver, ResolverConfig, Store};

let store = Store::in_memory()?;
let batch =
    BatchResolver::new(OfflineResolver, store.cache(), store.queue(), ResolverConfig::new("x"))
        .with_batch_size(0); // clamped to 1
Source

pub fn queue(&self) -> &dyn Queue

Borrow the underlying queue.

use simbad_resolver::{BatchResolver, OfflineResolver, ResolverConfig, Store};

let store = Store::in_memory()?;
let batch =
    BatchResolver::new(OfflineResolver, store.cache(), store.queue(), ResolverConfig::new("x"));
assert_eq!(batch.queue().pending_count().await?, 0);
Source

pub async fn enqueue(&self, id: &str, query: &str) -> Result<(), Error>

Enqueue an identifier keyed by an opaque caller id (idempotent).

use simbad_resolver::{BatchResolver, OfflineResolver, ResolverConfig, Store};

let store = Store::in_memory()?;
let batch =
    BatchResolver::new(OfflineResolver, store.cache(), store.queue(), ResolverConfig::new("x"));
batch.enqueue("job-1", "M31").await?;
batch.enqueue("job-1", "M31").await?; // idempotent: still one pending item
assert_eq!(batch.queue().pending_count().await?, 1);
Source

pub async fn drain(&self) -> Result<DrainSummary, Error>

Drain the pending queue once: resolve each pending item cache-first then online, marking resolved/unresolved or leaving it pending on a transient failure. Returns a DrainSummary. Terminates once every currently pending item has been processed (transiently-failed items are retried on a subsequent call).

See the struct-level example for a full seed-then-drain walkthrough.

use simbad_resolver::{BatchResolver, OfflineResolver, ResolverConfig, Store};

let store = Store::in_memory()?;
let batch =
    BatchResolver::new(OfflineResolver, store.cache(), store.queue(), ResolverConfig::new("x"));
batch.enqueue("job-1", "does-not-exist").await?;

// OfflineResolver reports `Disabled` (transient), so the item stays pending.
let summary = batch.drain().await?;
assert_eq!(summary.still_pending, 1);

Auto Trait Implementations§

§

impl<R> !RefUnwindSafe for BatchResolver<R>

§

impl<R> !UnwindSafe for BatchResolver<R>

§

impl<R> Freeze for BatchResolver<R>
where R: Freeze,

§

impl<R> Send for BatchResolver<R>

§

impl<R> Sync for BatchResolver<R>

§

impl<R> Unpin for BatchResolver<R>
where R: Unpin,

§

impl<R> UnsafeUnpin for BatchResolver<R>
where R: UnsafeUnpin,

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. 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