feat: Web concurrency (#2347)
* feat: Fork multiple processes * Remove boxen * comment * chore: Add support for Heroku DATABASE_CONNECTION_POOL_URL closes #2306
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
require("dotenv").config({ silent: true });
|
||||
|
||||
const errors = [];
|
||||
const boxen = require("boxen");
|
||||
const chalk = require("chalk");
|
||||
const throng = require("throng");
|
||||
|
||||
// If the DataDog agent is installed and the DD_API_KEY environment variable is
|
||||
// in the environment then we can safely attempt to start the DD tracer
|
||||
@@ -66,7 +66,7 @@ if (!process.env.URL) {
|
||||
);
|
||||
}
|
||||
|
||||
if (!process.env.DATABASE_URL) {
|
||||
if (!process.env.DATABASE_URL && !process.env.DATABASE_CONNECTION_POOL_URL) {
|
||||
errors.push(
|
||||
`The ${chalk.bold(
|
||||
"DATABASE_URL"
|
||||
@@ -95,11 +95,10 @@ if (errors.length) {
|
||||
|
||||
if (process.env.NODE_ENV === "production") {
|
||||
console.log(
|
||||
boxen(
|
||||
chalk.green(
|
||||
`
|
||||
Is your team enjoying Outline? Consider supporting future development by sponsoring the project:\n\nhttps://github.com/sponsors/outline
|
||||
`,
|
||||
{ padding: 1, margin: 1, borderStyle: "double", borderColor: "green" }
|
||||
`
|
||||
)
|
||||
);
|
||||
} else if (process.env.NODE_ENV === "development") {
|
||||
@@ -112,4 +111,11 @@ Is your team enjoying Outline? Consider supporting future development by sponsor
|
||||
);
|
||||
}
|
||||
|
||||
require("./main");
|
||||
const { start } = require("./main");
|
||||
|
||||
throng({
|
||||
worker: start,
|
||||
|
||||
// The number of workers to run, defaults to the number of CPUs available
|
||||
count: process.env.WEB_CONCURRENCY || undefined,
|
||||
});
|
||||
|
||||
@@ -234,10 +234,12 @@ server.on("listening", () => {
|
||||
console.log(`\n> Listening on http://localhost:${address.port}\n`);
|
||||
});
|
||||
|
||||
(async () => {
|
||||
export async function start(id: string) {
|
||||
console.log(`Started worker ${id}`);
|
||||
|
||||
await checkMigrations();
|
||||
server.listen(process.env.PORT || "3000");
|
||||
})();
|
||||
}
|
||||
|
||||
export const socketio = io;
|
||||
|
||||
|
||||
@@ -12,16 +12,19 @@ export const encryptedFields = () =>
|
||||
export const DataTypes = Sequelize;
|
||||
export const Op = Sequelize.Op;
|
||||
|
||||
export const sequelize = new Sequelize(process.env.DATABASE_URL, {
|
||||
logging: debug("sql"),
|
||||
typeValidation: true,
|
||||
dialectOptions: {
|
||||
ssl:
|
||||
isProduction && !isSSLDisabled
|
||||
? {
|
||||
// Ref.: https://github.com/brianc/node-postgres/issues/2009
|
||||
rejectUnauthorized: false,
|
||||
}
|
||||
: false,
|
||||
},
|
||||
});
|
||||
export const sequelize = new Sequelize(
|
||||
process.env.DATABASE_URL || process.env.DATABASE_CONNECTION_POOL_URL,
|
||||
{
|
||||
logging: debug("sql"),
|
||||
typeValidation: true,
|
||||
dialectOptions: {
|
||||
ssl:
|
||||
isProduction && !isSSLDisabled
|
||||
? {
|
||||
// Ref.: https://github.com/brianc/node-postgres/issues/2009
|
||||
rejectUnauthorized: false,
|
||||
}
|
||||
: false,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user