mirror of
https://github.com/4cuck/nitter-status.git
synced 2026-10-27 00:57:39 +00:00
cargo fmt and screenshot link
This commit is contained in:
1 parent
6be108ee64
commit
4e3f93f0c3
12 files changed
+152
-83
No files matched your search
+23
-13
@@ -18,8 +18,9 @@ use reqwest::{
|
||||
Client, Url,
|
||||
};
|
||||
use sea_orm::{
|
||||
sea_query::OnConflict, ActiveModelTrait, ActiveValue, ColumnTrait, DatabaseConnection,
|
||||
EntityTrait, QueryFilter, TransactionTrait, FromQueryResult, Statement, DbBackend, ConnectionTrait,
|
||||
sea_query::OnConflict, ActiveModelTrait, ActiveValue, ColumnTrait, ConnectionTrait,
|
||||
DatabaseConnection, DbBackend, EntityTrait, FromQueryResult, QueryFilter, Statement,
|
||||
TransactionTrait,
|
||||
};
|
||||
use thiserror::Error;
|
||||
use tokio::{task::JoinSet, time::sleep};
|
||||
@@ -83,9 +84,7 @@ impl FetchError {
|
||||
/// Returns the http status code, if applicable
|
||||
fn http_status_code(&self) -> Option<u16> {
|
||||
match self {
|
||||
FetchError::Reqwest(e) => {
|
||||
e.status().map(|v|v.as_u16())
|
||||
},
|
||||
FetchError::Reqwest(e) => e.status().map(|v| v.as_u16()),
|
||||
FetchError::HttpResponseStatus(code, _, _) => Some(*code),
|
||||
FetchError::KnownHttpResponseStatus(code, _) => Some(*code),
|
||||
FetchError::Captcha | FetchError::RetrievingBody(_, _) => None,
|
||||
@@ -93,7 +92,12 @@ impl FetchError {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run_scanner(db: DatabaseConnection, config: ScannerConfig, cache: Cache, disable_startup_scan: bool) -> Result<()> {
|
||||
pub fn run_scanner(
|
||||
db: DatabaseConnection,
|
||||
config: ScannerConfig,
|
||||
cache: Cache,
|
||||
disable_startup_scan: bool,
|
||||
) -> Result<()> {
|
||||
let scanner = Scanner::new(db, config, cache);
|
||||
|
||||
tokio::spawn(async move {
|
||||
@@ -194,9 +198,9 @@ impl Scanner {
|
||||
async fn sleep_till_deadline(&self) {
|
||||
let delay_instance_check =
|
||||
self.last_uptime_check() + self.inner.config.instance_check_interval;
|
||||
|
||||
|
||||
let delay_list_update = self.last_list_fetch() + self.inner.config.list_fetch_interval;
|
||||
|
||||
|
||||
let delay = delay_instance_check.min(delay_list_update);
|
||||
tracing::trace!(duration=?delay-Instant::now(),"scanner sleeping");
|
||||
sleep(delay.duration_since(Instant::now())).await;
|
||||
@@ -264,7 +268,10 @@ impl Scanner {
|
||||
// detect already offline host and prevent log spam
|
||||
let muted_host = match self.inner.config.auto_mute {
|
||||
false => false,
|
||||
true => last_status.iter().find(|v|v.domain == instance.domain).map_or(false,|check|!check.healthy),
|
||||
true => last_status
|
||||
.iter()
|
||||
.find(|v| v.domain == instance.domain)
|
||||
.map_or(false, |check| !check.healthy),
|
||||
};
|
||||
// tracing::trace!(muted_host,instance=?instance,last_status=?last_status);
|
||||
join_set.spawn(async move {
|
||||
@@ -278,12 +285,12 @@ impl Scanner {
|
||||
Ok(mut url) => {
|
||||
let rss = scanner_c.has_rss(&mut url, muted_host).await;
|
||||
match scanner_c.nitter_version(&mut url, muted_host).await {
|
||||
Some(version) => (rss,Some(version.version_name),Some(version.url)),
|
||||
None => (rss,None,None),
|
||||
Some(version) => (rss, Some(version.version_name), Some(version.url)),
|
||||
None => (rss, None, None),
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
host::ActiveModel {
|
||||
id: ActiveValue::NotSet,
|
||||
domain: ActiveValue::Set(instance.domain),
|
||||
@@ -376,7 +383,10 @@ impl Scanner {
|
||||
Ok((code, body))
|
||||
}
|
||||
|
||||
pub async fn query_latest_check<T: ConnectionTrait>(&self, connection: &T) -> Result<Vec<LatestCheck>> {
|
||||
pub async fn query_latest_check<T: ConnectionTrait>(
|
||||
&self,
|
||||
connection: &T,
|
||||
) -> Result<Vec<LatestCheck>> {
|
||||
let health_checks = LatestCheck::find_by_statement(Statement::from_sql_and_values(
|
||||
DbBackend::Sqlite,
|
||||
r#"
|
||||
|
||||
Reference in new issue
Block a user