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

Register a hook #91

Open
chasers opened this issue May 16, 2023 · 1 comment
Open

Register a hook #91

chasers opened this issue May 16, 2023 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@chasers
Copy link
Collaborator

chasers commented May 16, 2023

Note: Hooks v1 should be scoped to web hooks only. Break out function hooks into another issue later. Including here for comms on the final end state.

Hooks

We want to let users run semi-arbitrary code when certain things happen in the system. Users may want to do things when pools are spawned or destroyed. When certain kinds of SQL statements are submitted or when certain records are updated in the database.

  • A Hook can be a function hook (Postgres function call) or a web hook (http request)
  • Hooks can by sync or async

Function hooks

  • When you create a function hook it creates a hook record in the metadata database with the code required to create a Postgres function using a Postgres TLE language.
  • When a connection pool starts up Supavisor will create or replace all registered function hooks in the tenant database ensuring they exist.

Web hooks

  • Supavisor will manage making the http requests for web hooks.

Async hooks

  • Async hooks can be implemented as Telemetry events
  • A Telemetry event handler for a tenant database can attached to telemetry events based on hooks for a tenant in the metadata database
  • Example: like Realtime's Telemetry.Logger but instead of logging it would dynamically do what was registered with the hook, and the Telemetry events could be registered dynamically

Sync hooks

  • Sync hooks should be ran in between hook events and block until the hook response

Hook events

Hook evens will be generated from:

Unknown:

  • How would we let users address these?

Examples

As a db admin I want to turn my database to read-only mode when it's used a certain amount of storage

  • polling metric queries db size every minute
  • polling process emits a Telemetry event with db size
  • Telemetry hook handler matches on db size to trigger
  • Function registered with hook is called and includes ALTER SYSTEM SET default_transaction_read_only TO on;
  • Database is in read only mode now

As a dev I want my Stripe data updated in Stripe when I update a customer record in my database:

  • Register a synchronous function hook with code which will use http to make a request to Stripe
  • This hook will run on insert statements on a customers table for example
  • The insert will error to the SQL client if Stripe responds with an error

Prior Art

@chasers chasers added help wanted Extra attention is needed enhancement New feature or request labels May 16, 2023
@chasers chasers mentioned this issue May 16, 2023
2 tasks
@chasers chasers added this to the v1.0.0 milestone May 16, 2023
This was referenced May 16, 2023
@chasers chasers removed this from the v1.0.0 milestone Jul 31, 2023
@J0
Copy link
Contributor

J0 commented Dec 13, 2023

Hey @chasers

Just wondering is this still planned by any chance?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants