Skip to content

Commit

Permalink
use seconds for status timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
MicaiahReid committed Oct 3, 2023
1 parent 1b0146e commit 9cdbdef
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions components/chainhook-cli/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,14 +554,14 @@ pub struct ScanningData {
pub number_of_blocks_to_scan: u64,
pub number_of_blocks_evaluated: u64,
pub number_of_times_triggered: u64,
pub last_occurrence: Option<String>,
pub last_occurrence: Option<u64>,
pub last_evaluated_block_height: u64,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct StreamingData {
pub last_occurrence: Option<String>,
pub last_evaluation: String,
pub last_occurrence: Option<u64>,
pub last_evaluation: u64,
pub number_of_times_triggered: u64,
pub number_of_blocks_evaluated: u64,
pub last_evaluated_block_height: u64,
Expand All @@ -571,7 +571,7 @@ pub struct StreamingData {
pub struct ExpiredData {
pub number_of_blocks_evaluated: u64,
pub number_of_times_triggered: u64,
pub last_occurrence: Option<String>,
pub last_occurrence: Option<u64>,
pub last_evaluated_block_height: u64,
pub expired_at_block_height: u64,
}
Expand Down Expand Up @@ -664,11 +664,10 @@ fn set_predicate_streaming_status(
predicates_db_conn: &mut Connection,
ctx: &Context,
) {
let now_ms = SystemTime::now()
let now_secs = SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("Could not get current time in ms")
.as_millis()
.to_string();
.as_secs();
let (
last_occurrence,
number_of_blocks_evaluated,
Expand Down Expand Up @@ -733,7 +732,7 @@ fn set_predicate_streaming_status(
last_triggered_height,
triggered_count,
} => (
Some(now_ms.clone()),
Some(now_secs.clone()),
number_of_times_triggered + triggered_count,
number_of_blocks_evaluated + triggered_count,
last_triggered_height,
Expand All @@ -759,7 +758,7 @@ fn set_predicate_streaming_status(
predicate_key,
PredicateStatus::Streaming(StreamingData {
last_occurrence,
last_evaluation: now_ms,
last_evaluation: now_secs,
number_of_times_triggered,
last_evaluated_block_height,
number_of_blocks_evaluated,
Expand All @@ -781,38 +780,37 @@ pub fn set_predicate_scanning_status(
predicates_db_conn: &mut Connection,
ctx: &Context,
) {
let now_ms = SystemTime::now()
let now_secs = SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("Could not get current time in ms")
.as_millis()
.to_string();
.as_secs();
let current_status = retrieve_predicate_status(&predicate_key, predicates_db_conn);
let last_occurrence = match current_status {
Some(status) => match status {
PredicateStatus::Scanning(scanning_data) => {
if number_of_times_triggered > scanning_data.number_of_times_triggered {
Some(now_ms)
Some(now_secs)
} else {
scanning_data.last_occurrence
}
}
PredicateStatus::Streaming(streaming_data) => {
if number_of_times_triggered > streaming_data.number_of_times_triggered {
Some(now_ms)
Some(now_secs)
} else {
streaming_data.last_occurrence
}
}
PredicateStatus::UnconfirmedExpiration(expired_data) => {
if number_of_times_triggered > expired_data.number_of_times_triggered {
Some(now_ms)
Some(now_secs)
} else {
expired_data.last_occurrence
}
}
PredicateStatus::New => {
if number_of_times_triggered > 0 {
Some(now_ms)
Some(now_secs)
} else {
None
}
Expand Down

0 comments on commit 9cdbdef

Please sign in to comment.