maintain cluster polyfill in startup

broke when moved to polyfill
deepsource-autofix-76c6eb20
Dan Gowans 2023-02-28 10:23:51 -05:00
parent ae9bbc347f
commit 51f4376a78
5 changed files with 19 additions and 18 deletions

2
bin/www.d.ts vendored
View File

@ -1 +1 @@
import '../helpers/polyfills.js'; export {};

View File

@ -3,7 +3,6 @@ import os from 'node:os';
import { dirname } from 'node:path'; import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url'; import { fileURLToPath } from 'node:url';
import * as configFunctions from '../helpers/functions.config.js'; import * as configFunctions from '../helpers/functions.config.js';
import '../helpers/polyfills.js';
import exitHook from 'exit-hook'; import exitHook from 'exit-hook';
import ntfyPublish from '@cityssm/ntfy-publish'; import ntfyPublish from '@cityssm/ntfy-publish';
import Debug from 'debug'; import Debug from 'debug';
@ -12,9 +11,15 @@ const directoryName = dirname(fileURLToPath(import.meta.url));
const processCount = Math.min(configFunctions.getProperty('application.maximumProcesses'), os.cpus().length); const processCount = Math.min(configFunctions.getProperty('application.maximumProcesses'), os.cpus().length);
debug(`Primary pid: ${process.pid}`); debug(`Primary pid: ${process.pid}`);
debug(`Launching ${processCount} processes`); debug(`Launching ${processCount} processes`);
cluster.setupPrimary({ const clusterSettings = {
exec: directoryName + '/wwwProcess.js' exec: directoryName + '/wwwProcess.js'
}); };
if (cluster.setupPrimary) {
cluster.setupPrimary(clusterSettings);
}
else {
cluster.setupMaster(clusterSettings);
}
for (let index = 0; index < processCount; index += 1) { for (let index = 0; index < processCount; index += 1) {
cluster.fork(); cluster.fork();
} }

View File

@ -4,7 +4,6 @@ import { dirname } from 'node:path'
import { fileURLToPath } from 'node:url' import { fileURLToPath } from 'node:url'
import * as configFunctions from '../helpers/functions.config.js' import * as configFunctions from '../helpers/functions.config.js'
import '../helpers/polyfills.js'
import exitHook from 'exit-hook' import exitHook from 'exit-hook'
@ -24,9 +23,17 @@ const processCount = Math.min(
debug(`Primary pid: ${process.pid}`) debug(`Primary pid: ${process.pid}`)
debug(`Launching ${processCount} processes`) debug(`Launching ${processCount} processes`)
cluster.setupPrimary({ const clusterSettings = {
exec: directoryName + '/wwwProcess.js' exec: directoryName + '/wwwProcess.js'
}) }
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
if (cluster.setupPrimary) {
cluster.setupPrimary(clusterSettings)
} else {
// Maintain Node 14 support
cluster.setupMaster(clusterSettings)
}
for (let index = 0; index < processCount; index += 1) { for (let index = 0; index < processCount; index += 1) {
cluster.fork() cluster.fork()

View File

@ -1,4 +1,3 @@
import cluster from 'node:cluster';
import hasOwn from 'object.hasown'; import hasOwn from 'object.hasown';
import Debug from 'debug'; import Debug from 'debug';
const debug = Debug('lot-occupancy-system:polyfills'); const debug = Debug('lot-occupancy-system:polyfills');
@ -7,10 +6,6 @@ export function applyPolyfills() {
debug('Applying Object.hasOwn(o, v) polyfill'); debug('Applying Object.hasOwn(o, v) polyfill');
Object.hasOwn = hasOwn; Object.hasOwn = hasOwn;
} }
if (cluster.setupPrimary === undefined && cluster.setupMaster !== undefined) {
debug('Applying cluster.setupPrimary() polyfill');
cluster.setupPrimary = cluster.setupMaster;
}
} }
applyPolyfills(); applyPolyfills();
export default applyPolyfills; export default applyPolyfills;

View File

@ -1,4 +1,3 @@
import cluster from 'node:cluster'
import hasOwn from 'object.hasown' import hasOwn from 'object.hasown'
import Debug from 'debug' import Debug from 'debug'
@ -9,11 +8,6 @@ export function applyPolyfills(): void {
debug('Applying Object.hasOwn(o, v) polyfill') debug('Applying Object.hasOwn(o, v) polyfill')
Object.hasOwn = hasOwn Object.hasOwn = hasOwn
} }
if (cluster.setupPrimary === undefined && cluster.setupMaster !== undefined) {
debug('Applying cluster.setupPrimary() polyfill')
cluster.setupPrimary = cluster.setupMaster
}
} }
applyPolyfills() applyPolyfills()