Skip to content

Commit

Permalink
Add await_blocks to state parser
Browse files Browse the repository at this point in the history
  • Loading branch information
gemcoder21 committed Sep 6, 2023
1 parent 0ab8c86 commit 0427ba0
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
5 changes: 3 additions & 2 deletions parser/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ pub async fn main() {
match latest_block {
Ok(latest_block) => {
let _ = database_client.set_parser_state_latest_block(Chain::Binance, latest_block);
if state.current_block >= state.latest_block {
println!("parser ahead. current_block: {}, latest_block: {}", state.current_block, state.latest_block);
if state.current_block + state.await_blocks >= state.latest_block {

println!("parser ahead. current_block: {}, latest_block: {}, await_blocks: {}", state.current_block, state.latest_block, state.await_blocks);

thread::sleep(Duration::from_secs(2)); continue;
}
Expand Down
5 changes: 3 additions & 2 deletions storage/src/migrations/2023-09-03-220931_parser/up.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
CREATE TABLE parser_state (
chain VARCHAR NOT NULL PRIMARY KEY,
current_block INTEGER NOT NULL,
latest_block INTEGER NOT NULL,
current_block INTEGER NOT NULL default 0,
latest_block INTEGER NOT NULL default 0,
await_blocks INTEGER NOT NULL default 0,
is_enabled boolean NOT NULL default true,
updated_at timestamp NOT NULL default current_timestamp,
created_at timestamp NOT NULL default current_timestamp,
Expand Down
1 change: 1 addition & 0 deletions storage/src/models/parser_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ pub struct ParserState {
pub chain: String,
pub current_block: i32,
pub latest_block: i32,
pub await_blocks: i32,
pub is_enabled: bool,
}
1 change: 1 addition & 0 deletions storage/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ diesel::table! {
chain -> Varchar,
current_block -> Int4,
latest_block -> Int4,
await_blocks -> Int4,
is_enabled -> Bool,
updated_at -> Timestamp,
created_at -> Timestamp,
Expand Down

0 comments on commit 0427ba0

Please sign in to comment.