Skip to content

Commit 79d26e4

Browse files
committed
cleanup stray scheduler processes
1 parent c093f8a commit 79d26e4

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

resources/js/electron-plugin/src/index.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
retrieveNativePHPConfig,
88
retrievePhpIniSettings,
99
runScheduler,
10+
killScheduler,
1011
startAPI,
1112
startPhpApp,
1213
} from "./server/index.js";
@@ -22,8 +23,8 @@ const { autoUpdater } = electronUpdater;
2223

2324
class NativePHP {
2425
processes = [];
25-
schedulerInterval = undefined;
2626
mainWindow = null;
27+
schedulerInterval = undefined;
2728

2829
public bootstrap(
2930
app: CrossProcessExports.App,
@@ -244,12 +245,13 @@ class NativePHP {
244245
}
245246

246247

247-
private stopScheduler() {
248-
if (this.schedulerInterval) {
249-
clearInterval(this.schedulerInterval);
250-
this.schedulerInterval = null;
251-
}
252-
}
248+
private stopScheduler() {
249+
if (this.schedulerInterval) {
250+
clearInterval(this.schedulerInterval);
251+
this.schedulerInterval = null;
252+
}
253+
killScheduler();
254+
}
253255

254256
private startScheduler() {
255257
const now = new Date();
@@ -270,6 +272,8 @@ class NativePHP {
270272
}
271273

272274
private killChildProcesses() {
275+
this.stopScheduler();
276+
273277
this.processes
274278
.filter((p) => p !== undefined)
275279
.forEach((process) => {

resources/js/electron-plugin/src/server/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import {
77
} from "./php.js";
88
import { appendCookie } from "./utils.js";
99
import state from "./state.js";
10+
import { ChildProcess } from "child_process";
11+
12+
let schedulerProcess: ChildProcess | null = null;
1013

1114
export async function startPhpApp() {
1215
const result = await serveApp(
@@ -23,7 +26,15 @@ export async function startPhpApp() {
2326
}
2427

2528
export function runScheduler() {
26-
startScheduler(state.randomSecret, state.electronApiPort, state.phpIni);
29+
killScheduler();
30+
schedulerProcess = startScheduler(state.randomSecret, state.electronApiPort, state.phpIni);
31+
}
32+
33+
export function killScheduler() {
34+
if (schedulerProcess && !schedulerProcess.killed) {
35+
schedulerProcess.kill();
36+
schedulerProcess = null;
37+
}
2738
}
2839

2940
export function startAPI(): Promise<APIProcess> {

0 commit comments

Comments
 (0)