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

Ensure worker close gracefully with the same behaviours in both Terminal and Desktop apps #459

Open
wants to merge 26 commits into
base: main
Choose a base branch
from

Conversation

maidh91
Copy link
Contributor

@maidh91 maidh91 commented Nov 22, 2024

App Type

  • Terminal and Desktop apps can call Pear.Worker.run api to start Worker process
  • Parent/Worker can call pipe.end or pipe.destroy
  • These scenarios should be passed, and same behaviours in Terminal and Desktop apps

Scenarios

  • Parent calls pipe.end()

    • Worker receives end event
    • Worker receives close event
    • Worker is killed
    • Parent receives end event
    • Parent receives close event
  • Parent calls pipe.destroy()

    • Worker receives end event
    • Worker receives close event
    • Worker is killed
    • Parent receives close event only (no end event)
  • Worker calls pipe.end()

    • Worker receives end event
    • Worker receives close event
    • Worker is killed
    • Parent receives end event
    • Parent receives close event
  • Worker calls pipe.end()

    • Worker receives close event only (no end event)
    • Worker is killed
    • Parent receives end event
    • Parent receives close event

How to test

Sample Parent code

const pipe = Pear.worker.run('../worker-code')
pipe.on('data', (data) => {
  console.log(data.toString())
})
pipe.on('end', () => {
  console.log('end')
})
pipe.on('close', () => {
  console.log('close')
})
pipe.write('hello')
await new Promise((resolve) => setTimeout(resolve, 2000))
// pipe.end()
// pipe.destroy()
await new Promise((resolve) => setTimeout(resolve, 20000))

Sample Worker code

import fs from 'bare-fs'
const pipe = Pear.worker.pipe()
pipe.on('data', (data) => {
  pipe.write('world')
  fs.writeFileSync('/tmp/test-data', data.toString())
})
pipe.on('end', () => {
  fs.writeFileSync('/tmp/test-end', 'end')
})
pipe.on('close', () => {
  fs.writeFileSync('/tmp/test-close', 'close')
})
await new Promise((resolve) => setTimeout(resolve, 2000))
// pipe.end()
// pipe.destroy()
  • Run pear.dev run -d parent-code-dir
  • Uncomment pipe.end() or pipe.destroy()
  • Make sure Worker process is killed
  • Check /tmp/test-data, /tmp/test-end, /tmp/test-close for worker events

@maidh91 maidh91 changed the title ensure worker destroy gracefully ensure worker close gracefully Nov 22, 2024
@maidh91 maidh91 changed the title ensure worker close gracefully Ensure worker close gracefully Nov 22, 2024
@maidh91 maidh91 changed the title Ensure worker close gracefully Ensure worker close gracefully with the same behaviours in both Terminal and Desktop apps Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants