mirror of
https://github.com/spacebarchat/server.git
synced 2026-04-26 21:45:20 +00:00
Add ESLint (#941)
* Add eslint, switch to lint-staged for precommit * Fix all ESLint errors * Update GH workflow to check prettier and eslint
This commit is contained in:
@@ -24,7 +24,7 @@ import * as Api from "@fosscord/api";
|
||||
import * as Gateway from "@fosscord/gateway";
|
||||
import { CDNServer } from "@fosscord/cdn";
|
||||
import express from "express";
|
||||
import { green, bold, yellow } from "picocolors";
|
||||
import { green, bold } from "picocolors";
|
||||
import { Config, initDatabase, Sentry } from "@fosscord/util";
|
||||
|
||||
const app = express();
|
||||
|
||||
+11
-10
@@ -29,14 +29,15 @@ import { execSync } from "child_process";
|
||||
|
||||
const cores = process.env.THREADS ? parseInt(process.env.THREADS) : 1;
|
||||
|
||||
if (cluster.isPrimary) {
|
||||
function getCommitOrFail() {
|
||||
try {
|
||||
return execSync("git rev-parse HEAD").toString().trim();
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
function getCommitOrFail() {
|
||||
try {
|
||||
return execSync("git rev-parse HEAD").toString().trim();
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (cluster.isPrimary) {
|
||||
const commit = getCommitOrFail();
|
||||
|
||||
console.log(
|
||||
@@ -81,14 +82,14 @@ Cores: ${cyan(os.cpus().length)} (Using ${cores} thread(s).)
|
||||
// Fork workers.
|
||||
for (let i = 0; i < cores; i++) {
|
||||
// Delay each worker start if using sqlite database to prevent locking it
|
||||
let delay = process.env.DATABASE?.includes("://") ? 0 : i * 1000;
|
||||
const delay = process.env.DATABASE?.includes("://") ? 0 : i * 1000;
|
||||
setTimeout(() => {
|
||||
cluster.fork();
|
||||
console.log(`[Process] worker ${cyan(i)} started.`);
|
||||
}, delay);
|
||||
}
|
||||
|
||||
cluster.on("message", (sender: Worker, message: any) => {
|
||||
cluster.on("message", (sender: Worker, message) => {
|
||||
for (const id in cluster.workers) {
|
||||
const worker = cluster.workers[id];
|
||||
if (worker === sender || !worker) continue;
|
||||
@@ -96,7 +97,7 @@ Cores: ${cyan(os.cpus().length)} (Using ${cores} thread(s).)
|
||||
}
|
||||
});
|
||||
|
||||
cluster.on("exit", (worker: any, code: any, signal: any) => {
|
||||
cluster.on("exit", (worker) => {
|
||||
console.log(
|
||||
`[Worker] ${red(
|
||||
`died with PID: ${worker.process.pid} , restarting ...`,
|
||||
|
||||
Reference in New Issue
Block a user