tangle-network / relayer

🕸️ The Webb Relayer Network
https://webb-tools.github.io/relayer/
Apache License 2.0
22 stars 13 forks source link

Improve queue to track item progress #541

Closed salman01zp closed 1 year ago

salman01zp commented 1 year ago

Summary of changes

Update Queue system to include item status tracking and TTL feature. Items with pending status will only be processed and will be removed once TTL duration expires

pub struct QueueItem<T> {
    /// The inner value wrapped by the Queue Item.
    inner: T,
    /// The current state of the item in the queue.
    state: QueueItemState,
    /// The time when the item was enqueued.
    enqueued_at: u128,
    /// Time to live
    ttl: u128,
}

/// The status of the item in the queue.
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub enum QueueItemState {
    /// The current item is pending and waiting in the queue to be dequeued and processed.
    #[default]
    Pending,
    /// The item is being processed.
    Processing {
        /// A meaningful step for the current item state.
        step: String,
        /// A meaningful progress percentage for the current item state (0 to 1).
        progress: Option<f32>,
    },
    /// The item failed to be processed.
    Failed {
        /// The error message.
        reason: String,
    },
    /// The item was successfully processed.
    Processed,
}

Reference issue to close (if applicable)


Code Checklist

salman01zp commented 1 year ago

Will create separate PR to process private_tx withdraw through txqueue and with expose endpoint for item status tracking for Evm and Substrate chain

shekohex commented 1 year ago

Will review shortly.