quantus_cli/cli/
scheduler.rs1use crate::{chain::quantus_subxt, error::Result, log_print, log_success};
2use clap::Subcommand;
3
4#[derive(Subcommand, Debug)]
6pub enum SchedulerCommands {
7 GetLastProcessedTimestamp,
9}
10
11pub async fn get_last_processed_timestamp(
13 quantus_client: &crate::chain::client::QuantusClient,
14) -> Result<Option<u64>> {
15 use quantus_subxt::api;
16
17 log_print!("🕒 Getting last processed timestamp from the scheduler");
18
19 let storage_addr = api::storage().scheduler().last_processed_timestamp();
21
22 let latest_block_hash = quantus_client.get_latest_block().await?;
24
25 let storage_at = quantus_client.client().storage().at(latest_block_hash);
26
27 let timestamp = storage_at.fetch(&storage_addr).await.map_err(|e| {
28 crate::error::QuantusError::NetworkError(format!(
29 "Failed to fetch last processed timestamp: {e:?}"
30 ))
31 })?;
32
33 Ok(timestamp)
34}
35
36pub async fn handle_scheduler_command(command: SchedulerCommands, node_url: &str) -> Result<()> {
38 log_print!("🗓️ Scheduler");
39
40 let quantus_client = crate::chain::client::QuantusClient::new(node_url).await?;
41
42 match command {
43 SchedulerCommands::GetLastProcessedTimestamp => {
44 match get_last_processed_timestamp(&quantus_client).await? {
45 Some(timestamp) => {
46 log_success!("🎉 Last processed timestamp: {}", timestamp);
47 },
48 None => {
49 log_print!(
50 "🤷 No last processed timestamp found. The scheduler may not have run yet."
51 );
52 },
53 }
54 Ok(())
55 },
56 }
57}