Admin: list and restart running generations with the models set now
- Modellek page: analyses and answers being written or waiting, with their model and the one a restart would use; restart one or all - Each attempt's started_at is its token: a restarted attempt still running in the worker cannot write its result and is dropped within 10 seconds Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -1639,3 +1639,59 @@ async fn questions_about_an_analysis_use_question_units(pool: PgPool) {
|
||||
);
|
||||
assert_eq!(left().await, json!(5), "regenerating charges nobody");
|
||||
}
|
||||
|
||||
#[sqlx::test(migrator = "db::MIGRATOR")]
|
||||
async fn admins_restart_open_generations_with_the_current_models(pool: PgPool) {
|
||||
let app = TestApp::new(pool.clone()).await;
|
||||
let admin = app.register("admin@example.com", "Admin").await;
|
||||
let anna = app.register("anna@example.com", "Anna").await;
|
||||
assert_eq!(app.get("/v1/admin/jobs", Some(&anna)).await.status, StatusCode::FORBIDDEN);
|
||||
let put = |model: &str| {
|
||||
let (app, admin, body) = (&app, &admin, json!({ "model": model }));
|
||||
async move { app.call("PUT", "/v1/admin/models/analysis", Some(admin), Some(body)).await }
|
||||
};
|
||||
assert_eq!(put("openai/gpt-x").await.status, StatusCode::OK);
|
||||
let chart = app.chart(&admin, "Saját", true, "1990-03-15").await;
|
||||
let chart_id = chart["id"].as_str().unwrap();
|
||||
let r = app.post(&format!("/v1/charts/{chart_id}/analyses"), Some(&admin), json!({})).await;
|
||||
let id = r.body["id"].as_str().unwrap().to_string();
|
||||
// the worker is writing it with the chosen model
|
||||
sqlx::query("UPDATE analyses SET status = 'running', started_at = now(), attempts = 1 WHERE id = $1::uuid")
|
||||
.bind(&id)
|
||||
.execute(&pool)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
// after switching back to the default, the list shows what a restart would use
|
||||
assert_eq!(
|
||||
app.call("PUT", "/v1/admin/models/analysis", Some(&admin), Some(json!({"model": null}))).await.status,
|
||||
StatusCode::OK
|
||||
);
|
||||
let jobs = app.get("/v1/admin/jobs", Some(&admin)).await.body["jobs"].clone();
|
||||
let job = jobs.as_array().unwrap().iter().find(|j| j["id"] == json!(id)).expect("the analysis is listed");
|
||||
assert_eq!(
|
||||
(&job["status"], &job["model"], &job["next_model"]),
|
||||
(&json!("running"), &json!("openai/gpt-x"), &json!("anthropic/claude-test"))
|
||||
);
|
||||
|
||||
let r = app.post("/v1/admin/jobs/restart", Some(&admin), json!({ "ids": [id] })).await;
|
||||
assert_eq!((r.status, &r.body["restarted"]), (StatusCode::OK, &json!(1)), "{}", r.body);
|
||||
let (status, model, fallback, started, attempts): (
|
||||
String,
|
||||
String,
|
||||
Option<String>,
|
||||
Option<time::OffsetDateTime>,
|
||||
i32,
|
||||
) = sqlx::query_as("SELECT status, model, fallback_model, started_at, attempts FROM analyses WHERE id = $1::uuid")
|
||||
.bind(&id)
|
||||
.fetch_one(&pool)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
(status.as_str(), model.as_str(), fallback, started, attempts),
|
||||
("pending", "anthropic/claude-test", None, None, 0)
|
||||
);
|
||||
// finished ones are left alone
|
||||
sqlx::query("UPDATE analyses SET status = 'done', content = '{}'").execute(&pool).await.unwrap();
|
||||
assert_eq!(app.post("/v1/admin/jobs/restart", Some(&admin), json!({})).await.body["restarted"], 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user