Skip to content

Commit

Permalink
process and async state
Browse files Browse the repository at this point in the history
  • Loading branch information
longquanzheng committed Nov 9, 2023
1 parent cf81c7d commit d7ae38d
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 13 deletions.
8 changes: 0 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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
42 changes: 42 additions & 0 deletions src/xdb/async-state.ts
Original file line number Diff line number Diff line change
@@ -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<Input>{
stateOptions?:AsyncStateOptions
waitUntil?:WaitUntilMethod<Input>
execute(ctx:Context, input:Input, persistence:Persistence, communication :Communication):StateDecision
}

export interface WaitUntilMethod<Input>{
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<any>
// 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
}
3 changes: 3 additions & 0 deletions src/xdb/command-request.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface CommandRequest{
// TODO
}
4 changes: 4 additions & 0 deletions src/xdb/communication.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

export interface Communication{
// TODO
}
4 changes: 4 additions & 0 deletions src/xdb/context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

export interface Context{
// TODO
}
3 changes: 3 additions & 0 deletions src/xdb/persistence-schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface PersistenceSchema{
// TODO
}
3 changes: 3 additions & 0 deletions src/xdb/persistence.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface Persistence{
// TODO
}
21 changes: 21 additions & 0 deletions src/xdb/process.ts
Original file line number Diff line number Diff line change
@@ -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
}
3 changes: 3 additions & 0 deletions src/xdb/state-decision.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface StateDecision{
// TODO
}
3 changes: 3 additions & 0 deletions src/xdb/state-schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface StateSchema{
// TODO
}
7 changes: 2 additions & 5 deletions tests/add.test.ts
Original file line number Diff line number Diff line change
@@ -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")
});

0 comments on commit d7ae38d

Please sign in to comment.