fixed up the featured artist thing
This commit is contained in:
@@ -15,12 +15,27 @@ use crate::state::AppState;
|
||||
/// Spawn the unified scheduler background loop.
|
||||
pub fn spawn(state: web::Data<AppState>) {
|
||||
tokio::spawn(async move {
|
||||
// Initialize scheduler state rows in DB
|
||||
// Initialize scheduler state rows in DB with next_run_at pre-populated
|
||||
for job_name in ["pipeline", "monitor", "cookie_refresh"] {
|
||||
if let Err(e) =
|
||||
queries::scheduler_state::get_or_create(state.db.conn(), job_name).await
|
||||
{
|
||||
tracing::error!(job = job_name, error = %e, "failed to init scheduler state");
|
||||
match queries::scheduler_state::get_or_create(state.db.conn(), job_name).await {
|
||||
Ok(job) => {
|
||||
if job.next_run_at.is_none() {
|
||||
let (enabled, interval_secs) = read_job_config(&state, job_name).await;
|
||||
if enabled {
|
||||
let next =
|
||||
Utc::now().naive_utc() + chrono::Duration::seconds(interval_secs);
|
||||
let _ = queries::scheduler_state::update_next_run(
|
||||
state.db.conn(),
|
||||
job_name,
|
||||
Some(next),
|
||||
)
|
||||
.await;
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::error!(job = job_name, error = %e, "failed to init scheduler state");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,8 +70,7 @@ where
|
||||
// If config says disabled, ensure DB state reflects it
|
||||
if !config_enabled {
|
||||
if job.enabled {
|
||||
let _ =
|
||||
queries::scheduler_state::set_enabled(state.db.conn(), job_name, false).await;
|
||||
let _ = queries::scheduler_state::set_enabled(state.db.conn(), job_name, false).await;
|
||||
let _ =
|
||||
queries::scheduler_state::update_next_run(state.db.conn(), job_name, None).await;
|
||||
}
|
||||
@@ -103,8 +117,7 @@ where
|
||||
// Update last run and schedule next
|
||||
let _ = queries::scheduler_state::update_last_run(state.db.conn(), job_name, &result_str).await;
|
||||
let next = Utc::now().naive_utc() + chrono::Duration::seconds(interval_secs);
|
||||
let _ =
|
||||
queries::scheduler_state::update_next_run(state.db.conn(), job_name, Some(next)).await;
|
||||
let _ = queries::scheduler_state::update_next_run(state.db.conn(), job_name, Some(next)).await;
|
||||
}
|
||||
|
||||
async fn read_job_config(state: &web::Data<AppState>, job_name: &str) -> (bool, i64) {
|
||||
|
||||
Reference in New Issue
Block a user