Skip to content

Commit

Permalink
Awakeable identifiers following the new ID scheme
Browse files Browse the repository at this point in the history
Test Plan:

Using sample code to generate an awakeable and resolved it with
```
curl localhost:8080/dev.restate.Awakeables/Resolve -H 'content-type: application/json' -d '{"id": "awk_1NMyOAvDK2CcBjUH4Rmb7eGBp0DNNDnmsAAAAAQ", "json_result": ""}'
```

```
[restate] [2024-01-25T18:54:01.682Z] DEBUG: [CheckoutProcess/checkout] [inv_13q6r7rhzaG85fs0bfyqW8cubIUYJFjvBT] : Resuming (replaying) function.
Awakeable is:  awk_1NMyOAvDK2CcBjUH4Rmb7eGBp0DNNDnmsAAAAAQ
Awakeable COMPLETED  awk_1NMyOAvDK2CcBjUH4Rmb7eGBp0DNNDnmsAAAAAQ
```
  • Loading branch information
AhmedSoliman committed Jan 25, 2024
1 parent 766a642 commit 2c4333a
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@restatedev/restate-sdk",
"version": "0.7.0",
"version": "0.8.0",
"description": "Typescript SDK for Restate",
"engines": {
"node": ">= 10"
Expand Down
5 changes: 3 additions & 2 deletions src/restate_context_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
} from "./generated/proto/protocol";
import {
AWAKEABLE_ENTRY_MESSAGE_TYPE,
AWAKEABLE_IDENTIFIER_PREFIX,
BACKGROUND_INVOKE_ENTRY_MESSAGE_TYPE,
CLEAR_STATE_ENTRY_MESSAGE_TYPE,
COMPLETE_AWAKEABLE_ENTRY_MESSAGE_TYPE,
Expand Down Expand Up @@ -59,7 +60,7 @@ import {
import { rlog } from "./utils/logger";
import { Client, SendClient } from "./types/router";
import { RpcRequest, RpcResponse } from "./generated/proto/dynrpc";
import { requestFromArgs } from "./utils/assumpsions";
import { requestFromArgs } from "./utils/assumptions";
import { RandImpl } from "./utils/rand";

export enum CallContexType {
Expand Down Expand Up @@ -364,7 +365,7 @@ export class RestateGrpcContextImpl implements RestateGrpcContext {
);

return {
id: Buffer.concat([this.id, encodedEntryIndex]).toString("base64url"),
id: AWAKEABLE_IDENTIFIER_PREFIX + Buffer.concat([this.id, encodedEntryIndex]).toString("base64url"),
promise: promise,
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/server/base_restate_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import {
} from "../generated/proto/dynrpc";
import { RestateContext, useContext } from "../restate_context";
import { RpcContextImpl } from "../restate_context_impl";
import { verifyAssumptions } from "../utils/assumpsions";
import { verifyAssumptions } from "../utils/assumptions";
import { TerminalError } from "../public_api";
import { isEventHandler } from "../types/router";
import { jsonSafeAny } from "../utils/utils";
Expand Down
2 changes: 2 additions & 0 deletions src/types/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ export const BACKGROUND_INVOKE_ENTRY_MESSAGE_TYPE = 0x0c02n;
export const AWAKEABLE_ENTRY_MESSAGE_TYPE = 0x0c03n;
export const COMPLETE_AWAKEABLE_ENTRY_MESSAGE_TYPE = 0x0c04n;

export const AWAKEABLE_IDENTIFIER_PREFIX = "awk_1";

// Export the custom message types
// Side effects are custom messages because the runtime does not need to inspect them
export const SIDE_EFFECT_ENTRY_MESSAGE_TYPE = 0xfc01n;
Expand Down
6 changes: 3 additions & 3 deletions src/utils/assumpsions.ts → src/utils/assumptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ export const verifyAssumptions = (
isKeyed: boolean,
request: RpcRequest
): { key?: string; request?: JsType } => {
const assumpsion = request.senderAssumes ?? 0;
switch (assumpsion) {
const assumption = request.senderAssumes ?? 0;
switch (assumption) {
case 0: {
// no assumption: this comes from an ingress.
const hasKeyProperty =
Expand Down Expand Up @@ -124,7 +124,7 @@ export const verifyAssumptions = (
}
default: {
throw new TerminalError(
`Unknown assumption id ${assumpsion}. This indicates an incorrect (or involuntary) setting of the assumption property at the ingress request, or an SDK bug.`
`Unknown assumption id ${assumption}. This indicates an incorrect (or involuntary) setting of the assumption property at the ingress request, or an SDK bug.`
);
}
}
Expand Down

0 comments on commit 2c4333a

Please sign in to comment.