Skip to content

Commit c1fe509

Browse files
committed
Kill parent PID
1 parent 9b56ad8 commit c1fe509

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

benchmark/apps/cli/src/index.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ const testCommands: Record<ExerciseLanguage, { commands: string[]; timeout?: num
4343
rust: { commands: ["cargo test"] }, // timeout 15s bash -c "cd '$dir' && cargo test > /dev/null 2>&1"
4444
}
4545

46+
let parentPid: number | undefined = undefined
47+
4648
const run = async (toolbox: GluegunToolbox) => {
4749
const { config, prompt } = toolbox
4850

@@ -124,6 +126,10 @@ const run = async (toolbox: GluegunToolbox) => {
124126

125127
const result = await finishRun(run.id)
126128
console.log("[cli#run]", result)
129+
130+
if (parentPid) {
131+
console.log(await execa`kill -INT ${parentPid}`)
132+
}
127133
}
128134

129135
const runExercise = async ({ run, task, server }: { run: Run; task: Task; server: IpcServer }) => {
@@ -137,8 +143,20 @@ const runExercise = async ({ run, task, server }: { run: Run; task: Task; server
137143
})`code -n ${path.resolve(exercisesPath, language, exercise)}`
138144

139145
console.log(`Connecting to ${taskSocketPath}`)
146+
147+
const createClient = (taskSocketPath: string) => {
148+
const ipcClient = new IpcClient(taskSocketPath)
149+
150+
ipcClient.on(IpcMessageType.Ack, (ack) => {
151+
console.log(`[cli#runExercise | ${language} / ${exercise}] ack`, ack)
152+
parentPid = ack.ppid
153+
})
154+
155+
return ipcClient
156+
}
157+
140158
let tries = 0
141-
let client = new IpcClient(taskSocketPath)
159+
let client = createClient(taskSocketPath)
142160

143161
while (++tries < 5) {
144162
try {
@@ -147,7 +165,7 @@ const runExercise = async ({ run, task, server }: { run: Run; task: Task; server
147165
} catch (error) {
148166
console.error(error)
149167
client.disconnect()
150-
client = new IpcClient(taskSocketPath)
168+
client = createClient(taskSocketPath)
151169
}
152170
}
153171

@@ -159,8 +177,9 @@ const runExercise = async ({ run, task, server }: { run: Run; task: Task; server
159177

160178
let isTaskFinished = false
161179

162-
client.on(IpcMessageType.Disconnect, () => {
180+
client.on(IpcMessageType.Disconnect, async () => {
163181
console.log(`[cli#runExercise | ${language} / ${exercise}] disconnect`)
182+
// await updateTask(task.id, { finishedAt: new Date() })
164183
isTaskFinished = true
165184
})
166185

0 commit comments

Comments
 (0)