-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: initial crawlers states * refactor: rename status to state * fix: some fixes * feat: crawlers state endpoint * chore: crawler state cleanup * chore: fmt fix * feat: use crawler in interval crawlers * chore: fmt fix * fix: transactions crawler starting from last saved transaction * feat: fix upserts and remove clear_db call * feat: make interval crawlers processing right away * feat: return timestamp 0 when no values in the db
- Loading branch information
1 parent
5f5d94e
commit 0aa9369
Showing
79 changed files
with
1,762 additions
and
830 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use anyhow::Context; | ||
use chrono::NaiveDateTime; | ||
use diesel::upsert::excluded; | ||
use diesel::{ExpressionMethods, PgConnection, RunQueryDsl}; | ||
use orm::crawler_state::{ChainStateInsertDb, CrawlerNameDb}; | ||
use orm::schema::crawler_state; | ||
use shared::crawler_state::{ChainCrawlerState, CrawlerName}; | ||
|
||
pub fn upsert_crawler_state( | ||
transaction_conn: &mut PgConnection, | ||
crawler_state: ChainCrawlerState, | ||
) -> anyhow::Result<()> { | ||
diesel::insert_into(crawler_state::table) | ||
.values::<&ChainStateInsertDb>( | ||
&(CrawlerName::Chain, crawler_state).into(), | ||
) | ||
.on_conflict(crawler_state::name) | ||
.do_update() | ||
.set(( | ||
crawler_state::timestamp.eq(excluded(crawler_state::timestamp)), | ||
crawler_state::last_processed_block | ||
.eq(excluded(crawler_state::last_processed_block)), | ||
crawler_state::last_processed_epoch | ||
.eq(excluded(crawler_state::last_processed_epoch)), | ||
)) | ||
.execute(transaction_conn) | ||
.context("Failed to update crawler state in db")?; | ||
|
||
anyhow::Ok(()) | ||
} | ||
|
||
pub fn update_crawler_timestamp( | ||
transaction_conn: &mut PgConnection, | ||
timestamp: NaiveDateTime, | ||
) -> anyhow::Result<()> { | ||
diesel::update(crawler_state::table) | ||
.filter(crawler_state::name.eq(CrawlerNameDb::from(CrawlerName::Chain))) | ||
.set(crawler_state::timestamp.eq(timestamp)) | ||
.execute(transaction_conn) | ||
.context("Failed to update crawler timestamp in db")?; | ||
|
||
anyhow::Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
pub mod balance; | ||
pub mod crawler; | ||
pub mod crawler_state; | ||
pub mod gov; | ||
pub mod pos; | ||
pub mod revealed_pk; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.