-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Event firehose #419
Comments
Thinking about When doing that, you end up in a double-write scenario, but maybe that's generally a better trade-off; to simply that use case we could provide an update function to the hook that re-saves the data but bypasses any further hooks / processes etc. Like this: postCreate: async (event, update) => {
// Only trigger it if it's in the past, or there's no event time set (ie; immediate)
if (!event.triggerTime || event.triggerTime < now()) {
sendToZapier(event.type, event.data);
update({ triggered: true });
}
} The argument could potentially be an Really most actions performed in hooks should go through the main While we're on that API, another interesting feature could be passing a preCreate: async (event, { context }) => {
if (condition(event)) context.something = true;
},
postCreate: async (event, { context, update }) => {
if (context.something) {
update({ definitelySaved: true });
}
} This might be an interesting way to allow cross-cutting logic between hooks, potentially even across multiple instances of the lifecycle events if that's a thing (e.g because plugins, etc). It does effectively introduce a global object, however, which could be bad if misused. Finally - not sure which issue to link this to - but what happens if we |
Good points about the pre/post hooks - didn't think of those failure cases! We already pass
This is something that needs to be fleshed out more. A A |
Most of the current hook chat is in #244.
If I'm understanding you correctly this gets back to the "layers" of hooks we've discussed previously. There may be hooks at the GraphQL layer, and possibly hooks at the Keystone list API layer and maybe even developer-added hook-like operations happening at the ORM or DB layer (eg. Mongoose hooks, DB triggers). However since each layer only/always operates on the layer below it shouldn't be possible to form loops. I'm actually not sure this issue belongs in the Keystone repo. All the generic parts of this (email interface: #292, email queue: #293, workers: #307, hooks: #244) are described elsewhere (albeit not yet spec'ed or implemented). The usage of these generic tools (to build an event firehose) seems pretty project specific to me... am I wrong? |
Hooking up to something like Amazon's new EventBridge would be 👌 for logging and all sorts of other uses. |
Now that our list & field hooks are much more fleshed out, that gives me all the extension points I need to trigger events. As for time-based events, that's still on my todo list. However, I no long expect Keystone to handle this for me. Instead, I might look to something like BullMQ or Bee-Queue instead. |
Related to #292 / #293.
Context
The end goal is to be able to send emails when one of the following conditions are true:
This problem can be broken down into 2 halves:
The act of sending the emails (2) can be handled by something like Zapier or ifttt for my usecase.
This issues is mostly about (1): Triggering events.
Triggers
The two triggers present different challenges, with different solutions
Mutation based
This one is mostly solved with pre/post hooks.
I think we need to expose those hooks at a list-config level, but the logic is already there for triggering them on various CRUD operations.
It then becomes a matter of making the correct call to Zapier / ifttt within a hook:
Time based
This one is a bit trickier - time based triggers require some kind of state.
There's a possibility that ifttt / Zapier support handling that state (ie; we tell Zapier when to trigger something we send it). However, that adds complexity around updates / cancellations of events.
Another option is to ditch the idea of time-based and say "Hey user; if you want to send emails to your members, you'll have to set an alarm on your smart phone, then trigger an event" (See Bike Shedding for a method of triggering events via a write to an
Events
list, which can be done in the admin UI)Bike Shedding
There may be a need to keep track of what events have been sent, so instead of sending to Zapier in the
Event
'spostCreate
hook, we might setup a separate list like so:Then for time-based ones, we could run an independent cron job every 1s, that looks for unsent events:
The text was updated successfully, but these errors were encountered: