Skip to content

Commit

Permalink
refactor(daemon): Remove extraneous worker process args (merge #2213)
Browse files Browse the repository at this point in the history
Removes extraneous arguments to worker processes.
  • Loading branch information
rekmarks authored Apr 16, 2024
2 parents b71d7d1 + 16a66e1 commit 3457c7e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 40 deletions.
23 changes: 6 additions & 17 deletions packages/daemon/src/daemon-node-powers.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,8 @@ export const makeDaemonicControlPowers = (
* @param {Promise<never>} cancelled
*/
const makeWorker = async (workerId, daemonWorkerFacet, cancelled) => {
const { cachePath, statePath, ephemeralStatePath, sockPath } = config;
const { statePath, ephemeralStatePath } = config;

const workerCachePath = filePowers.joinPath(cachePath, 'worker', workerId);
const workerStatePath = filePowers.joinPath(statePath, 'worker', workerId);
const workerEphemeralStatePath = filePowers.joinPath(
ephemeralStatePath,
Expand All @@ -474,21 +473,11 @@ export const makeDaemonicControlPowers = (
const pidPath = filePowers.joinPath(workerEphemeralStatePath, 'worker.pid');

const log = fs.openSync(logPath, 'a');
const child = popen.fork(
endoWorkerPath,
[
workerId,
sockPath,
workerStatePath,
workerEphemeralStatePath,
workerCachePath,
],
{
stdio: ['ignore', log, log, 'pipe', 'pipe', 'ipc'],
// @ts-ignore Stale Node.js type definition.
windowsHide: true,
},
);
const child = popen.fork(endoWorkerPath, [], {
stdio: ['ignore', log, log, 'pipe', 'pipe', 'ipc'],
// @ts-ignore Stale Node.js type definition.
windowsHide: true,
});
const workerPid = child.pid;
const nodeWriter = /** @type {import('stream').Writable} */ (
child.stdio[3]
Expand Down
21 changes: 1 addition & 20 deletions packages/daemon/src/worker-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,6 @@ import { makePromiseKit } from '@endo/promise-kit';
import { main } from './worker.js';
import { makePowers } from './worker-node-powers.js';

if (process.argv.length < 7) {
throw new Error(
`worker.js requires arguments workerUuid, daemonSockPath, workerStatePath, workerEphemeralStatePath, workerCachePath, got ${process.argv.join(
', ',
)}`,
);
}

const [workerUuid, sockPath, statePath, ephemeralStatePath, cachePath] =
process.argv.slice(2);

/** @type {import('./types.js').Config} */
const config = {
sockPath,
statePath,
ephemeralStatePath,
cachePath,
};

const powers = makePowers({ fs, url });

const { promise: cancelled, reject: cancel } =
Expand All @@ -44,7 +25,7 @@ process.once('SIGINT', () => cancel(new Error('SIGINT')));

// @ts-ignore Yes, we can assign to exitCode, typedoc.
process.exitCode = 1;
main(powers, config, workerUuid, process.pid, cancel, cancelled).then(
main(powers, process.pid, cancel, cancelled).then(
() => {
process.exitCode = 0;
},
Expand Down
4 changes: 1 addition & 3 deletions packages/daemon/src/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,11 @@ export const makeWorkerFacet = ({ cancel }) => {

/**
* @param {import('./types.js').MignonicPowers} powers
* @param {import('./types.js').Config} _config
* @param {string} _uuid
* @param {number | undefined} pid
* @param {(error: Error) => void} cancel
* @param {Promise<never>} cancelled
*/
export const main = async (powers, _config, _uuid, pid, cancel, cancelled) => {
export const main = async (powers, pid, cancel, cancelled) => {
console.error(`Endo worker started on pid ${pid}`);
cancelled.catch(() => {
console.error(`Endo worker exiting on pid ${pid}`);
Expand Down

0 comments on commit 3457c7e

Please sign in to comment.