Skip to content

Commit 6a59b44

Browse files
authored
Merge pull request #1946 from Kobzol/migrations-after-workqueue
Run migrations after loading the workqueue
2 parents da64ec5 + 012ef41 commit 6a59b44

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/main.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,6 @@ async fn serve_req(
245245
}
246246

247247
async fn run_server(addr: SocketAddr) -> anyhow::Result<()> {
248-
let db_url = std::env::var("DATABASE_URL").expect("needs DATABASE_URL");
249-
let pool = db::ClientPool::new(db_url.clone());
250-
db::run_migrations(&mut *pool.get().await)
251-
.await
252-
.context("database migrations")?;
253-
254248
let gh = github::GithubClient::new_from_env();
255249
let oc = octocrab::OctocrabBuilder::new()
256250
.personal_token(github::default_token_from_env())
@@ -275,6 +269,17 @@ async fn run_server(addr: SocketAddr) -> anyhow::Result<()> {
275269
};
276270
tracing::info!("Workqueue loaded");
277271

272+
// Only run the migrations after the workqueue has been loaded, immediately
273+
// before starting the HTTP server.
274+
// On AWS ECS, triagebot shortly runs in two instances at once.
275+
// We thus want to minimize the time where migrations have been executed
276+
// and the old instance potentially runs on an newer database schema.
277+
let db_url = std::env::var("DATABASE_URL").expect("needs DATABASE_URL");
278+
let pool = db::ClientPool::new(db_url.clone());
279+
db::run_migrations(&mut *pool.get().await)
280+
.await
281+
.context("database migrations")?;
282+
278283
let ctx = Arc::new(Context {
279284
username: std::env::var("TRIAGEBOT_USERNAME").or_else(|err| match err {
280285
std::env::VarError::NotPresent => Ok("rustbot".to_owned()),

0 commit comments

Comments
 (0)