From 6af13cf2795b0ceea83abb9ba66c4ba3fb1cc504 Mon Sep 17 00:00:00 2001 From: Giselle van Dongen Date: Mon, 18 Nov 2024 13:56:20 +0100 Subject: [PATCH] Fix missing awaits and comments --- basics/basics-typescript/src/3_workflows.ts | 10 +++++++--- basics/basics-typescript/src/4_virtual_objects.ts | 6 +++--- basics/basics-typescript/src/5_events_processing.ts | 2 +- basics/basics-typescript/src/utils/example_stubs.ts | 2 +- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/basics/basics-typescript/src/3_workflows.ts b/basics/basics-typescript/src/3_workflows.ts index 1c7254b5..6538c138 100644 --- a/basics/basics-typescript/src/3_workflows.ts +++ b/basics/basics-typescript/src/3_workflows.ts @@ -29,7 +29,6 @@ const myWorkflow = restate.workflow({ handlers: { run: async (ctx: restate.WorkflowContext, params: { name: string; email: string }) => { const {name, email} = params; - const userId = ctx.key; // publish state, for the world to see our progress ctx.set("stage", "Creating User"); @@ -41,7 +40,7 @@ const myWorkflow = restate.workflow({ // send the email with the verification secret const secret = ctx.rand.uuidv4(); - ctx.run(() => sendEmailWithLink({email, secret})); + await ctx.run(() => sendEmailWithLink({email, secret})); try { // the promise here is resolved or rejected by the additional workflow methods below @@ -83,7 +82,12 @@ export type WorkflowApi = typeof myWorkflow; // ---------- ⬆️⬆️ deploy this as a container, lambda, etc. ⬆️⬆️ ---------- // start it via an HTTP call. -// `curl restate:8080/usersignup/signup-userid1/run/send --json '{ "name": "Bob", "email": "bob@builder.com" }' +// curl localhost:8080/usersignup/signup-userid1/run/send --json '{ "name": "Bob", "email": "bob@builder.com" }' +// +// Resolve the email link via: +// curl localhost:8080/usersignup/signup-userid1/verifyEmail +// Abort the email verification via: +// curl localhost:8080/usersignup/signup-userid1/abortVerification // or programmatically async function signupUser(userId: string, name: string, email: string) { diff --git a/basics/basics-typescript/src/4_virtual_objects.ts b/basics/basics-typescript/src/4_virtual_objects.ts index c9774d5c..675490c6 100644 --- a/basics/basics-typescript/src/4_virtual_objects.ts +++ b/basics/basics-typescript/src/4_virtual_objects.ts @@ -52,9 +52,9 @@ const greeterObject = restate.object({ // you can call this now through http directly the following way -example1: `curl localhost:8080/greeter/mary/greet -H 'content-type: application/json' -d '{ "greeting" : "Hi" }'`; -example2: `curl localhost:8080/greeter/barack/greet -H 'content-type: application/json' -d '{"greeting" : "Hello" }'`; -example3: `curl localhost:8080/greeter/mary/ungreet -H 'content-type: application/json' -d '{}'`; +// example1: `curl localhost:8080/greeter/mary/greet -H 'content-type: application/json' -d '{ "greeting" : "Hi" }'`; +// example2: `curl localhost:8080/greeter/barack/greet -H 'content-type: application/json' -d '{"greeting" : "Hello" }'`; +// example3: `curl localhost:8080/greeter/mary/ungreet -H 'content-type: application/json' -d '{}'`; // --------------------------------- deploying -------------------------------- diff --git a/basics/basics-typescript/src/5_events_processing.ts b/basics/basics-typescript/src/5_events_processing.ts index 99884810..b4f494bb 100644 --- a/basics/basics-typescript/src/5_events_processing.ts +++ b/basics/basics-typescript/src/5_events_processing.ts @@ -46,7 +46,7 @@ const userUpdates = restate.object({ // The other events for this Virtual Object / key are queued. // Events for other keys are processed concurrently. // The sleep suspends the function (e.g., when running on FaaS). - ctx.sleep(5_000); + await ctx.sleep(5_000); userId = await ctx.run(() => updateUserProfile(profile)); } diff --git a/basics/basics-typescript/src/utils/example_stubs.ts b/basics/basics-typescript/src/utils/example_stubs.ts index 049b4e50..8dd828c2 100644 --- a/basics/basics-typescript/src/utils/example_stubs.ts +++ b/basics/basics-typescript/src/utils/example_stubs.ts @@ -81,7 +81,7 @@ export async function tryApplyPermission( const { permissionKey, setting } = permission; maybeCrash(0.3); // sometimes infra goes away - if (setting !== "blocked") { + if (setting !== "block") { applicationError( 0.4, `Could not apply permission ${permissionKey}:${setting} for user ${userId} due to a conflict.`