Skip to content

Conversation

@stnguyen90
Copy link
Contributor

What does this PR do?

Trigger events using database listeners

We initially designed events to trigger via labels on the endpoint. the problem with this approach was triggering multiple events per endpoint became very messy.

Test Plan

TBD

Related PRs and Issues

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs?

throw new Exception(Exception::DATABASE_NOT_FOUND);
}

$events->setContext('database', $db);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This context is required by some events so we have to make sure to set it before the DB operation so it's available in the handler.

Comment on lines +706 to +708
$events->setContext('token', new Document([
'secret' => $loginSecret,
]));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unhashed secret is required in the event, so pass it to the handler using context.

app/init.php Outdated
Comment on lines 1220 to 1233
switch ($collection) {
case 'users':
if (!\str_starts_with($eventPattern, 'users.[userId]')) {
$eventPattern = 'users.[userId]';
$eventPatternReady = false;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverse engineering the event pattern given the collection feels a little hacky.

->setAttribute('hash', Auth::DEFAULT_ALGO)
->setAttribute('hashOptions', Auth::DEFAULT_ALGO_OPTIONS);
$dbForProject->updateDocument('users', $profile->getId(), $profile);
$dbForProject->silent(fn () => $dbForProject->updateDocument('users', $profile->getId(), $profile));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrapping with silent to disable all listeners might be dangerous.

@stnguyen90 stnguyen90 force-pushed the feat-2406-multiple-events branch 2 times, most recently from 1ea5e58 to 138856f Compare June 16, 2023 01:07
We initially designed events to trigger via labels on the endpoint. the
problem with this approach was triggering multiple events per endpoint
became very messy.
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.

3 participants