@@ -245,12 +245,6 @@ async fn serve_req(
245
245
}
246
246
247
247
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
-
254
248
let gh = github:: GithubClient :: new_from_env ( ) ;
255
249
let oc = octocrab:: OctocrabBuilder :: new ( )
256
250
. personal_token ( github:: default_token_from_env ( ) )
@@ -275,6 +269,17 @@ async fn run_server(addr: SocketAddr) -> anyhow::Result<()> {
275
269
} ;
276
270
tracing:: info!( "Workqueue loaded" ) ;
277
271
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
+
278
283
let ctx = Arc :: new ( Context {
279
284
username : std:: env:: var ( "TRIAGEBOT_USERNAME" ) . or_else ( |err| match err {
280
285
std:: env:: VarError :: NotPresent => Ok ( "rustbot" . to_owned ( ) ) ,
0 commit comments