Skip to content

Commit

Permalink
refactor: make handler process private
Browse files Browse the repository at this point in the history
  • Loading branch information
dnalborczyk committed Aug 13, 2022
1 parent 2089eb0 commit df0c474
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/lambda/handler-runner/python-runner/PythonRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export default class PythonRunner {

#env = null

#handlerProcess = null

#runtime = null

constructor(funOptions, env) {
Expand All @@ -38,7 +40,7 @@ export default class PythonRunner {

const [pythonExecutable] = this.#runtime.split('.')

this.handlerProcess = spawn(
this.#handlerProcess = spawn(
pythonExecutable,
[
'-u',
Expand All @@ -52,14 +54,14 @@ export default class PythonRunner {
},
)

this.handlerProcess.stdout.readline = createInterface({
input: this.handlerProcess.stdout,
this.#handlerProcess.stdout.readline = createInterface({
input: this.#handlerProcess.stdout,
})
}

// () => void
cleanup() {
this.handlerProcess.kill()
this.#handlerProcess.kill()
}

#parsePayload(value) {
Expand Down Expand Up @@ -113,8 +115,8 @@ export default class PythonRunner {
try {
const parsed = this.#parsePayload(line.toString())
if (parsed) {
this.handlerProcess.stdout.readline.removeListener('line', onLine)
this.handlerProcess.stderr.removeListener('data', onErr)
this.#handlerProcess.stdout.readline.removeListener('line', onLine)
this.#handlerProcess.stderr.removeListener('data', onErr)
return accept(parsed)
}
return null
Expand All @@ -123,12 +125,12 @@ export default class PythonRunner {
}
}

this.handlerProcess.stdout.readline.on('line', onLine)
this.handlerProcess.stderr.on('data', onErr)
this.#handlerProcess.stdout.readline.on('line', onLine)
this.#handlerProcess.stderr.on('data', onErr)

process.nextTick(() => {
this.handlerProcess.stdin.write(input)
this.handlerProcess.stdin.write('\n')
this.#handlerProcess.stdin.write(input)
this.#handlerProcess.stdin.write('\n')
})
})
}
Expand Down

0 comments on commit df0c474

Please sign in to comment.