Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
26 changes: 13 additions & 13 deletions src/modules/cli/lib/cli-events-subscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,6 @@ import { sendIpcEventToRenderer } from 'src/ipc-utils';
import { executeCliCommand } from 'src/modules/cli/lib/execute-command';
import { SiteServer } from 'src/site-server';

const cliSiteEventSchema = z.object( {
action: z.literal( 'keyValuePair' ),
key: z.literal( 'site-event' ),
value: z
.string()
.transform( ( val ) => JSON.parse( val ) )
.pipe( siteEventSchema ),
} );

let subscriber: ReturnType< typeof executeCliCommand > | null = null;

function siteDetailsToServerDetails(
site: SiteDetails,
running: boolean,
Expand Down Expand Up @@ -70,6 +59,17 @@ const handleSiteEvent = sequential( async ( event: SiteEvent ): Promise< void >
void sendIpcEventToRenderer( 'site-event', event );
} );

const cliSiteEventSchema = z.object( {
action: z.literal( 'keyValuePair' ),
key: z.literal( 'site-event' ),
value: z
.string()
.transform( ( val ) => JSON.parse( val ) )
.pipe( siteEventSchema ),
} );

let subscriber: ReturnType< typeof executeCliCommand > | null = null;
Comment on lines +62 to +71
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just moved these definitions closer to where they're used


export async function startCliEventsSubscriber(): Promise< void > {
return new Promise( ( resolve, reject ) => {
if ( subscriber ) {
Expand Down Expand Up @@ -111,8 +111,8 @@ export async function startCliEventsSubscriber(): Promise< void > {

export function stopCliEventsSubscriber(): void {
if ( subscriber ) {
const [ , childProcess ] = subscriber;
const [ eventEmitter, childProcess ] = subscriber;
eventEmitter.removeAllListeners();
childProcess.kill( 'SIGKILL' );
subscriber = null;
}
}
9 changes: 8 additions & 1 deletion src/modules/cli/lib/execute-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,14 @@ export function executeCliCommand(
function appQuitHandler() {
const pid = child.pid;
const result = child.kill();
console.log( `Child process with pid ${ pid } killed with result: ${ result }` );
if ( result ) {
console.log( `Successfully killed child process with pid ${ pid }` );
} else {
console.error(
`Failed to kill child process with pid ${ pid }. This likely means the process is already terminated. CLI args:`,
args
);
Comment on lines +113 to +116
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unrelated to the core purpose of this PR, but it will help us debug if there's ever an issue with unterminated child processes.

}
}

child.on( 'close', ( code ) => {
Expand Down