From d7ae38df6abac9197b41d104cc91bd495b3ddd34 Mon Sep 17 00:00:00 2001 From: Quanzheng Long Date: Thu, 9 Nov 2023 15:48:56 -0800 Subject: [PATCH] process and async state --- src/index.ts | 8 ------- src/xdb/async-state.ts | 42 +++++++++++++++++++++++++++++++++++ src/xdb/command-request.ts | 3 +++ src/xdb/communication.ts | 4 ++++ src/xdb/context.ts | 4 ++++ src/xdb/persistence-schema.ts | 3 +++ src/xdb/persistence.ts | 3 +++ src/xdb/process.ts | 21 ++++++++++++++++++ src/xdb/state-decision.ts | 3 +++ src/xdb/state-schema.ts | 3 +++ tests/add.test.ts | 7 ++---- 11 files changed, 88 insertions(+), 13 deletions(-) create mode 100644 src/xdb/async-state.ts create mode 100644 src/xdb/command-request.ts create mode 100644 src/xdb/communication.ts create mode 100644 src/xdb/context.ts create mode 100644 src/xdb/persistence-schema.ts create mode 100644 src/xdb/persistence.ts create mode 100644 src/xdb/process.ts create mode 100644 src/xdb/state-decision.ts create mode 100644 src/xdb/state-schema.ts diff --git a/src/index.ts b/src/index.ts index cdc6f9b..5715432 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,9 +1 @@ import {Configuration} from 'xdb-ts-api' -// -// console.log(new Configuration()) - -export function add(a: number, b: number): number { - return a + b; -} - -console.log(add(3, 5)); //output: 8 \ No newline at end of file diff --git a/src/xdb/async-state.ts b/src/xdb/async-state.ts new file mode 100644 index 0000000..71ad117 --- /dev/null +++ b/src/xdb/async-state.ts @@ -0,0 +1,42 @@ +import {RetryPolicy} from 'xdb-ts-api' +import {Context} from "./context"; +import {Persistence} from "./persistence"; +import {Communication} from "./communication"; +import {StateDecision} from "./state-decision"; +import {CommandRequest} from "./command-request"; + +export interface AsyncState{ + stateOptions?:AsyncStateOptions + waitUntil?:WaitUntilMethod + execute(ctx:Context, input:Input, persistence:Persistence, communication :Communication):StateDecision +} + +export interface WaitUntilMethod{ + waitUntil(ctx:Context, input:Input, communication: Communication):CommandRequest +} +export interface AsyncStateOptions{ + // waitUntilTimeoutSeconds is the timeout for the waitUntil API call. + // Default: 10 seconds(configurable in server) when set as 0 + // It will be capped to 60 seconds by server (configurable in server) + waitUntilTimeoutSeconds?: number + // executeTimeoutSeconds is the timeout for the execute API call. + // Default: 10 seconds(configurable in server) when set as 0 + // It will be capped to 60 seconds by server (configurable in server) + executeTimeoutSeconds?: number + // waitUntilRetryPolicy is the retry policy for the waitUntil API call. + // Default: infinite retry with 1 second initial interval, 120 seconds max interval, and 2 backoff factor, + // when set as nil + waitUntilRetryPolicy?:RetryPolicy + // executeRetryPolicy is the retry policy for the execute API call. + // Default: infinite retry with 1 second initial interval, 120 seconds max interval, and 2 backoff factor, + // when set as nil + executeRetryPolicy?:RetryPolicy + // failureRecoveryState is the state to recover after current state execution fails + // Default: no recovery when set as nil + failureRecoveryState?: AsyncState + // persistencePolicyName is the name of loading policy for persistence if not using default policy + persistencePolicyName?:string + // stateId is the unique identifier of the state. + // It is being used for WorkerService to choose the right AsyncState to execute Start/Execute APIs + stateId?: string +} \ No newline at end of file diff --git a/src/xdb/command-request.ts b/src/xdb/command-request.ts new file mode 100644 index 0000000..cf1125d --- /dev/null +++ b/src/xdb/command-request.ts @@ -0,0 +1,3 @@ +export interface CommandRequest{ + // TODO +} \ No newline at end of file diff --git a/src/xdb/communication.ts b/src/xdb/communication.ts new file mode 100644 index 0000000..cc23c14 --- /dev/null +++ b/src/xdb/communication.ts @@ -0,0 +1,4 @@ + +export interface Communication{ + // TODO +} \ No newline at end of file diff --git a/src/xdb/context.ts b/src/xdb/context.ts new file mode 100644 index 0000000..c8ec08e --- /dev/null +++ b/src/xdb/context.ts @@ -0,0 +1,4 @@ + +export interface Context{ + // TODO +} \ No newline at end of file diff --git a/src/xdb/persistence-schema.ts b/src/xdb/persistence-schema.ts new file mode 100644 index 0000000..1c7b1bf --- /dev/null +++ b/src/xdb/persistence-schema.ts @@ -0,0 +1,3 @@ +export interface PersistenceSchema{ + // TODO +} \ No newline at end of file diff --git a/src/xdb/persistence.ts b/src/xdb/persistence.ts new file mode 100644 index 0000000..f0117e7 --- /dev/null +++ b/src/xdb/persistence.ts @@ -0,0 +1,3 @@ +export interface Persistence{ + // TODO +} \ No newline at end of file diff --git a/src/xdb/process.ts b/src/xdb/process.ts new file mode 100644 index 0000000..51bb56f --- /dev/null +++ b/src/xdb/process.ts @@ -0,0 +1,21 @@ +import {StateSchema} from "./state-schema"; +import {PersistenceSchema} from "./persistence-schema"; +import {ProcessIdReusePolicy} from "xdb-ts-api"; + +export interface Process{ + stateSchema?:StateSchema + persistenceSchema?:PersistenceSchema + processOptions?:ProcessOptions +} + +export interface ProcessOptions{ + // TimeoutSeconds is the timeout for the process execution. + // Default: 0, mean which means infinite timeout + timeoutSeconds?:number + // IdReusePolicy is the policy for reusing process id. + // Default: xdbapi.ALLOW_IF_NO_RUNNING when set as nil + idReusePolicy?:ProcessIdReusePolicy + // processType defines the processType of this process definition. + // GetFinalProcessType set the default value when return empty string + processType?:string +} \ No newline at end of file diff --git a/src/xdb/state-decision.ts b/src/xdb/state-decision.ts new file mode 100644 index 0000000..a240aa9 --- /dev/null +++ b/src/xdb/state-decision.ts @@ -0,0 +1,3 @@ +export interface StateDecision{ + // TODO +} \ No newline at end of file diff --git a/src/xdb/state-schema.ts b/src/xdb/state-schema.ts new file mode 100644 index 0000000..a8d86dd --- /dev/null +++ b/src/xdb/state-schema.ts @@ -0,0 +1,3 @@ +export interface StateSchema{ + // TODO +} \ No newline at end of file diff --git a/tests/add.test.ts b/tests/add.test.ts index 6c060c3..d6b819e 100644 --- a/tests/add.test.ts +++ b/tests/add.test.ts @@ -1,6 +1,3 @@ -import { add } from '../src'; - -test('adds two numbers correctly', () => { - const result = add(2, 3); - expect(result).toBe(5); +test('TODO', () => { + console.log("hello world") });