Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(node/cluster): cluster module for Node compat #2271

Merged
merged 30 commits into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
e954f2b
feat: `primary.ts` implementation for `cluster` compat module
cmorten May 25, 2022
a7b5c98
feat: flesh out cluster implementation
cmorten May 26, 2022
45eef43
docs: add copyright notices
cmorten May 26, 2022
76aa486
Update node/cluster.ts
cmorten May 26, 2022
e59c163
fix: formatting
cmorten May 26, 2022
0c6a178
Merge branch 'main' into feat/node-worker-compat
cmorten May 26, 2022
f729723
fix: dynamic import not playing nice
cmorten May 26, 2022
d47c392
test: env var check in `cluster` module requires permission
cmorten May 26, 2022
de185ab
chore: types
cmorten May 26, 2022
f204b21
kick ci
cmorten May 26, 2022
c792377
feat: support cluster in `net` module
cmorten May 27, 2022
10e8b56
refactor: remove cluster test as process methods not implemented yet
cmorten May 31, 2022
3498a74
fix: formatting
cmorten May 31, 2022
2adda6c
fix: remove unused variable
cmorten May 31, 2022
6643834
Merge branch 'main' into feat/node-worker-compat
cmorten Dec 20, 2022
1e9d5e1
refactor: reinstate ForkOptions from merge conflict
cmorten Dec 20, 2022
58e5df5
fix: align types
cmorten Dec 20, 2022
c000c4d
refactor: appease linter
cmorten Dec 20, 2022
7a4a6fc
fix: also export cluster as named export
cmorten Dec 20, 2022
61fd701
fix: formatting
cmorten Dec 20, 2022
f857bd5
fix: appease linter
cmorten Dec 20, 2022
3b8919d
refactor: everything an object?
cmorten Dec 20, 2022
c0c16f6
Merge branch 'main' into feat/node-worker-compat
cmorten Jan 3, 2023
67d877d
chore: copyright dates
cmorten Jan 3, 2023
f811ac8
refactor: lazy load circular dep classes
cmorten Jan 4, 2023
29ce19e
revert: default object export
cmorten Jan 4, 2023
ced5aa4
fix: cluster exports
cmorten Jan 4, 2023
b6d63da
test: remove cluster tests that fail on ubuntu
cmorten Jan 4, 2023
8f06eb2
chore: kick ci
cmorten Jan 4, 2023
75f6f6f
fix: `_fs_access_test.ts`
cmorten Jan 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions node/child_process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,26 @@ const denoCompatArgv = [
"--no-check",
"--allow-all",
];

export interface ForkOptions extends ChildProcessOptions {
execPath?: string | undefined;
execArgv?: string[] | undefined;
silent?: boolean | undefined;
}

/**
* Spawns a new Node.js process + fork.
* @param modulePath
* @param args
* @param option
* @returns {ChildProcess}
*/
export function fork(modulePath: string, options?: ForkOptions): ChildProcess;
export function fork(
modulePath: string,
args?: ReadonlyArray<string>,
options?: ForkOptions,
): ChildProcess;
export function fork(
modulePath: string, /* args?: string[], options?: ForkOptions*/
) {
Expand Down
71 changes: 6 additions & 65 deletions node/cluster.ts
Original file line number Diff line number Diff line change
@@ -1,69 +1,10 @@
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Copyright Joyent, Inc. and Node.js contributors. All rights reserved. MIT license.

import { notImplemented } from "./_utils.ts";
import process from "./process.ts";

/** A Worker object contains all public information and method about a worker.
* In the primary it can be obtained using cluster.workers. In a worker it can
* be obtained using cluster.worker.
*/
export class Worker {
constructor() {
notImplemented("cluster.Worker.prototype.constructor");
}
}
/** Calls .disconnect() on each worker in cluster.workers. */
export function disconnected() {
notImplemented("cluster.disconnected");
}
/** Spawn a new worker process. */
export function fork() {
notImplemented("cluster.fork");
}
/** True if the process is a primary. This is determined by
* the process.env.NODE_UNIQUE_ID. If process.env.NODE_UNIQUE_ID is undefined,
* then isPrimary is true. */
export const isPrimary = undefined;
/** True if the process is not a primary (it is the negation of
* cluster.isPrimary). */
export const isWorker = undefined;
/** Deprecated alias for cluster.isPrimary. details. */
export const isMaster = isPrimary;
/** The scheduling policy, either cluster.SCHED_RR for round-robin or
* cluster.SCHED_NONE to leave it to the operating system. This is a global
* setting and effectively frozen once either the first worker is spawned, or
* .setupPrimary() is called, whichever comes first. */
export const schedulingPolicy = undefined;
/** The settings object */
export const settings = undefined;
/** Deprecated alias for .setupPrimary(). */
export function setupMaster() {
notImplemented("cluster.setupMaster");
}
/** setupPrimary is used to change the default 'fork' behavior. Once called,
* the settings will be present in cluster.settings. */
export function setupPrimary() {
notImplemented("cluster.setupPrimary");
}
/** A reference to the current worker object. Not available in the primary
* process. */
export const worker = undefined;
/** A hash that stores the active worker objects, keyed by id field. Makes it
* easy to loop through all the workers. It is only available in the primary
* process. */
export const workers = undefined;
const childOrPrimary = "NODE_UNIQUE_ID" in process.env ? "child" : "primary";

export default {
Worker,
disconnected,
fork,
isPrimary,
isWorker,
isMaster,
schedulingPolicy,
settings,
setupMaster,
setupPrimary,
worker,
workers,
};
const exports = await import(`internal/cluster/${childOrPrimary}.ts`);
cmorten marked this conversation as resolved.
Show resolved Hide resolved

export default exports;
Loading