sui_indexer_builder/
lib.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4pub mod indexer_builder;
5pub mod metrics;
6pub mod progress;
7pub mod sui_datasource;
8pub const LIVE_TASK_TARGET_CHECKPOINT: i64 = i64::MAX;
9
10#[derive(Clone, Debug)]
11pub struct Task {
12    pub task_name: String,
13    pub start_checkpoint: u64,
14    pub target_checkpoint: u64,
15    pub timestamp: u64,
16    pub is_live_task: bool,
17}
18
19impl Task {
20    // TODO: this is really fragile and we should fix the task naming thing and storage schema asasp
21    pub fn name_prefix(&self) -> &str {
22        self.task_name.split(' ').next().unwrap_or("Unknown")
23    }
24
25    pub fn type_str(&self) -> &str {
26        if self.is_live_task {
27            "live"
28        } else {
29            "backfill"
30        }
31    }
32}
33
34#[derive(Clone, Debug)]
35pub struct Tasks {
36    live_task: Option<Task>,
37    backfill_tasks: Vec<Task>,
38}
39
40impl Tasks {
41    pub fn new(tasks: Vec<Task>) -> anyhow::Result<Self> {
42        let mut live_tasks = vec![];
43        let mut backfill_tasks = vec![];
44        for task in tasks {
45            if task.is_live_task {
46                live_tasks.push(task);
47            } else {
48                backfill_tasks.push(task);
49            }
50        }
51        if live_tasks.len() > 1 {
52            anyhow::bail!("More than one live task found: {:?}", live_tasks);
53        }
54        Ok(Self {
55            live_task: live_tasks.pop(),
56            backfill_tasks,
57        })
58    }
59
60    pub fn live_task(&self) -> Option<Task> {
61        self.live_task.clone()
62    }
63
64    pub fn backfill_tasks_ordered_desc(&self) -> Vec<Task> {
65        let mut tasks = self.backfill_tasks.clone();
66        tasks.sort_by(|t1, t2| t2.start_checkpoint.cmp(&t1.start_checkpoint));
67        tasks
68    }
69}