pub struct BlockHandlerScheduler { /* private fields */ }Expand description
Manages block-level handler scheduling and execution.
The scheduler maintains a list of interval handlers (which fire every N blocks) and setup handlers (which fire once). It determines when each handler should run and executes them in registration order.
Implementations§
Source§impl BlockHandlerScheduler
impl BlockHandlerScheduler
Sourcepub fn register_interval(&mut self, handler: Arc<dyn IntervalHandler>)
pub fn register_interval(&mut self, handler: Arc<dyn IntervalHandler>)
Register an interval handler.
Handlers are executed in registration order when their interval is due.
Sourcepub fn register_setup(&mut self, handler: Arc<dyn SetupHandler>)
pub fn register_setup(&mut self, handler: Arc<dyn SetupHandler>)
Register a setup handler.
Setup handlers run once during run_setup, in registration order.
Sourcepub async fn run_setup(
&mut self,
ctx: &IndexContext,
) -> Result<(), IndexerError>
pub async fn run_setup( &mut self, ctx: &IndexContext, ) -> Result<(), IndexerError>
Run all setup handlers once.
This method is idempotent — calling it more than once has no effect. Returns an error if any setup handler fails.
Sourcepub async fn run_block(
&self,
block: &BlockSummary,
ctx: &IndexContext,
) -> Result<(), IndexerError>
pub async fn run_block( &self, block: &BlockSummary, ctx: &IndexContext, ) -> Result<(), IndexerError>
Run all interval handlers that are due for the given block.
A handler fires when block.number % handler.interval() == 0.
Handlers are executed in registration order.
Sourcepub fn should_run_interval(
&self,
handler: &dyn IntervalHandler,
block_number: u64,
) -> bool
pub fn should_run_interval( &self, handler: &dyn IntervalHandler, block_number: u64, ) -> bool
Check whether an interval handler should fire at the given block number.
Returns true if block_number % interval == 0. An interval of 0 is
treated as “never fire” to avoid division by zero.
Sourcepub fn is_setup_complete(&self) -> bool
pub fn is_setup_complete(&self) -> bool
Returns whether setup has been completed.
Sourcepub fn interval_handler_count(&self) -> usize
pub fn interval_handler_count(&self) -> usize
Returns the number of registered interval handlers.
Sourcepub fn setup_handler_count(&self) -> usize
pub fn setup_handler_count(&self) -> usize
Returns the number of registered setup handlers.