Skip to content
Merged
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions retail/interactive-tutorials/events/rejoin-user-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// [START retail_rejoin_user_events]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

By adding region tags, this code snippet is now likely to be used in documentation, so it's important to ensure it follows best practices and is free of bugs. I've noticed a couple of issues in the enclosed code:

  • Missing await: The call to utils.purgeUserEvents(parent, visitorId) on line 67 is not awaited. purgeUserEvents is an async function, and without await, the main function might complete and the script exit before the purge operation is sent to the server. This would cause the cleanup step to fail silently, leaving test data behind. The fix is to change the line to await utils.purgeUserEvents(parent, visitorId);.

  • Hardcoded Enum: The UserEventRejoinScope enum is defined locally on lines 32-36. It's better practice to use the enum provided by the @google-cloud/retail client library, if it's exported. Using the library's enum makes the code more robust against future API changes.

Since I cannot comment directly on the affected lines (67 and 32-36) due to tooling limitations, I'm leaving this comment here on the start of the region tag. Please address these issues to improve the quality of this code sample.


'use strict';

Expand Down Expand Up @@ -72,3 +73,5 @@ process.on('unhandledRejection', err => {
});

main();

// [END retail_rejoin_user_events]