Skip to content

Commit

Permalink
fix missing
Browse files Browse the repository at this point in the history
  • Loading branch information
longquanzheng committed Nov 20, 2023
1 parent 86d782f commit a8a5687
Show file tree
Hide file tree
Showing 13 changed files with 155 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/sdk-typescript.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions src/xcherry/async-state.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import {RetryPolicy} from 'xcherry-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> {
// stateId is a required field to identify the state definition
// It must be unique in all the states in the same process definition.
// It's recommended to just use the Class name of the state as the stateId.
stateId: string
// asyncStateOptions is the options for the async state
stateOptions?: AsyncStateOptions
// waitUntil is the optional method to implement the waitUntil API call.
// waitUntil API will return a commandRequest for server to wait for.
// After the commandRequest is completed, the execute API will be invoked.
// if waitUntil is not implemented, the execute API will be invoked immediately.
waitUntil?: WaitUntilMethod<Input>

// execute is the required method to implement the execute API call.
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
}
3 changes: 3 additions & 0 deletions src/xcherry/command-request.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface CommandRequest {
// TODO
}
3 changes: 3 additions & 0 deletions src/xcherry/communication.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface Communication {
// TODO
}
3 changes: 3 additions & 0 deletions src/xcherry/context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface Context {
// TODO
}
3 changes: 3 additions & 0 deletions src/xcherry/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/xcherry/persistence.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface Persistence {
// TODO
}
25 changes: 25 additions & 0 deletions src/xcherry/process.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {StateSchema} from "./state-schema";
import {PersistenceSchema} from "./persistence-schema";
import {ProcessIdReusePolicy} from "xcherry-ts-api";

export interface Process {
// processType is a required field to identify the process type.
// It must be unique in all the processes registered in the same registry.
// It's recommended to just use the Class name of the process as the processType.
processType: string
// stateSchema is to define the async states of the process.
stateSchema?: StateSchema
// persistenceSchema is to define the persistence schema of the process.
persistenceSchema?: PersistenceSchema
// processOptions is the options for the process
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
}
3 changes: 3 additions & 0 deletions src/xcherry/state-decision.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface StateDecision {
// TODO
}
30 changes: 30 additions & 0 deletions src/xcherry/state-schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {AsyncState} from "./async-state";

export interface StateSchema {
startingState: AsyncState<any> | null | undefined
nonStartingStates: AsyncState<any>[]
}

export function newStateSchema(
startingState: AsyncState<any>,
...nonStartingState: AsyncState<any>[]
): StateSchema {
return new stateSchema(startingState, ...nonStartingState);
}

export function newStateSchemaNoStartingState(
...nonStartingState: AsyncState<any>[]
): StateSchema {
return new stateSchema(null, ...nonStartingState);
}

class stateSchema implements StateSchema {
nonStartingStates: AsyncState<any>[];
startingState: AsyncState<any> | null | undefined;

constructor(startingState: AsyncState<any> | null, ...nonStartingState: AsyncState<any>[]) {
this.nonStartingStates = nonStartingState;
this.startingState = startingState;
}
}

0 comments on commit a8a5687

Please sign in to comment.