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

feat(events): add events system #155

Merged
merged 10 commits into from
Dec 9, 2020
Merged

feat(events): add events system #155

merged 10 commits into from
Dec 9, 2020

Conversation

benjie
Copy link
Member

@benjie benjie commented Dec 2, 2020

Description

There's lots of events that happen inside of Graphile Worker that library consumers might be interested in; this PR raises these events with an event system.

IMPORTANT: people registering event handlers MUST make sure that these handlers do NOT throw errors. We've wrapped the emit with a try/catch that swallows the error in the two most dangerous places, but consumers must be certain that errors are not thrown as this may cause unexpected states of the work queue to take place.

Events added so far:

  • pool:create - When a worker pool is created
  • pool:listen:connecting - When a worker pool attempts to connect to PG ready to issue a LISTEN statement
  • pool:listen:success - When a worker pool starts listening for jobs via PG LISTEN
  • pool:listen:error - When a worker pool faces an error on their PG LISTEN client
  • pool:release - When a worker pool is released
  • pool:gracefulShutdown - When a worker pool starts a graceful shutdown
  • pool:gracefulShutdown:error - When a worker pool graceful shutdown throws an error
  • worker:create - When a worker is created
  • worker:release - When release of a worker is requested
  • worker:stop - When a worker stops (normally after a release)
  • worker:getJob:error - When a worker calls get_job but there are no available jobs
  • worker:getJob:empty - When a worker calls get_job but there are no available jobs
  • worker:fatalError - When a worker is created
  • job:start - When a job is retrieved by get_job
  • job:success - When a job completes successfully
  • job:error - When a job throws an error
  • job:failed - When a job fails permanently (emitted after job:error when appropriate)
  • gracefulShutdown - When the runner is terminated by a signal
  • stop - When the runner is stopped

Fixes #28

Performance impact

There must be an impact, but it seems too small to show up in benchmarks.

Security impact

None known.

@benjie
Copy link
Member Author

benjie commented Dec 2, 2020

This PR also re-orders some logic; I'm going to pull that out into a separate PR to keep this one cleaner.

@shicholas
Copy link

shicholas commented Dec 6, 2020

this looks amazing, my only question above is how one would subscribe to the EventEmitter?

@benjie
Copy link
Member Author

benjie commented Dec 7, 2020

Great question @shicholas; does the above couple commits address this question sufficiently?

@shicholas
Copy link

yes, thanks!

@benjie benjie merged commit 04a4422 into main Dec 9, 2020
@benjie benjie deleted the hooks branch December 9, 2020 12:25
@benjie benjie mentioned this pull request Mar 4, 2024
6 tasks
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.

Add hooks/events
2 participants