minorfix3
All checks were successful
deploy / deploy (push) Successful in 59s

This commit is contained in:
Untone 2024-10-22 12:58:01 +03:00
parent 3019652d8b
commit a25e16132c
2 changed files with 1 additions and 13 deletions

View File

@ -2,8 +2,7 @@ use actix_web::error::ErrorInternalServerError;
use aws_config::BehaviorVersion; use aws_config::BehaviorVersion;
use aws_sdk_s3::{config::Credentials, Client as S3Client}; use aws_sdk_s3::{config::Credentials, Client as S3Client};
use redis::{aio::MultiplexedConnection, AsyncCommands, Client as RedisClient}; use redis::{aio::MultiplexedConnection, AsyncCommands, Client as RedisClient};
use std::{env, time::Duration}; use std::env;
use tokio::time::interval;
use std::collections::HashMap; use std::collections::HashMap;
use log::info; use log::info;
use crate::s3_utils::get_s3_filelist; use crate::s3_utils::get_s3_filelist;
@ -17,7 +16,6 @@ pub struct AppState {
} }
const PATH_MAPPING_KEY: &str = "filepath_mapping"; // Ключ для хранения маппинга путей const PATH_MAPPING_KEY: &str = "filepath_mapping"; // Ключ для хранения маппинга путей
const CHECK_INTERVAL_SECONDS: u64 = 60 * 60; // Интервал обновления списка файлов: 1 час
const WEEK_SECONDS: u64 = 604800; const WEEK_SECONDS: u64 = 604800;
impl AppState { impl AppState {
@ -117,15 +115,6 @@ impl AppState {
// Преобразуем HashMap в Vec<String>, используя значения (пути файлов) // Преобразуем HashMap в Vec<String>, используя значения (пути файлов)
cached_list.into_values().collect() cached_list.into_values().collect()
} }
/// Периодически обновляет кэшированный список файлов из Storj S3.
pub async fn refresh_file_list_periodically(&self) {
let mut interval = interval(Duration::from_secs(CHECK_INTERVAL_SECONDS));
loop {
interval.tick().await;
self.cache_storj_filelist().await;
}
}
/// Получает путь в Storj из ключа (имени файла) в Redis. /// Получает путь в Storj из ключа (имени файла) в Redis.
pub async fn get_path(&self, file_key: &str) -> Result<Option<String>, actix_web::Error> { pub async fn get_path(&self, file_key: &str) -> Result<Option<String>, actix_web::Error> {

View File

@ -23,7 +23,6 @@ async fn main() -> std::io::Result<()> {
let rt = tokio::runtime::Handle::current(); let rt = tokio::runtime::Handle::current();
rt.block_on(async move { rt.block_on(async move {
app_state_clone.cache_storj_filelist().await; app_state_clone.cache_storj_filelist().await;
app_state_clone.refresh_file_list_periodically().await;
}); });
}); });