Discourse stuck with 504 Gateway Time-Out error and 100% CPU after rebuild

I’ve waited 30 minutes or more.