Skip to content

Commit

Permalink
feat: Add Schedule API (#937)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjameswh authored Nov 7, 2022
1 parent 66e85cb commit 808e562
Show file tree
Hide file tree
Showing 13 changed files with 2,553 additions and 11 deletions.
27 changes: 25 additions & 2 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
"@grpc/grpc-js": "^1.6.7",
"@temporalio/common": "file:../common",
"@temporalio/proto": "file:../proto",
"ms": "^2.1.3",
"long": "^5.2.0",
"uuid": "^8.3.2"
},
"devDependencies": {
"@types/long": "^5.0.0",
"protobufjs": "^7.0.0"
},
"bugs": {
Expand Down
14 changes: 14 additions & 0 deletions packages/client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import os from 'os';
import { AsyncCompletionClient } from './async-completion-client';
import { Connection } from './connection';
import { ClientInterceptors } from './interceptors';
import { ScheduleClient } from './schedule-client';
import { ConnectionLike, Metadata, WorkflowService } from './types';
import { WorkflowClient } from './workflow-client';

Expand Down Expand Up @@ -95,6 +96,12 @@ export class Client {
* (Async) Activity completion sub-client - use to manually manage Activities
*/
public readonly activity: AsyncCompletionClient;
/**
* Schedule sub-client - use to start and interact with Schedules
*
* @experimental
*/
public readonly schedule: ScheduleClient;

constructor(options?: ClientOptions) {
this.connection = options?.connection ?? Connection.lazy();
Expand All @@ -119,6 +126,13 @@ export class Client {
connection: this.connection,
dataConverter: loadedDataConverter,
});

this.schedule = new ScheduleClient({
...base,
connection: this.connection,
dataConverter: loadedDataConverter,
interceptors: interceptors.schedule,
});
}

/**
Expand Down
2 changes: 2 additions & 0 deletions packages/client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ export * from './interceptors';
export * from './types';
export * from './workflow-client';
export * from './workflow-options';
export * from './schedule-types';
export * from './schedule-client';
34 changes: 33 additions & 1 deletion packages/client/src/interceptors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import { Headers, Next } from '@temporalio/common';
import { temporal } from '@temporalio/proto';
import { CompiledScheduleOptions } from './schedule-types';
import {
DescribeWorkflowExecutionResponse,
RequestCancelWorkflowExecutionResponse,
Expand Down Expand Up @@ -131,11 +132,42 @@ export interface WorkflowClientInterceptors {
calls?: WorkflowClientCallsInterceptorFactory[];
}

/**
* Implement any of these methods to intercept ScheduleClient outbound calls
*
* @experimental
*/
export interface ScheduleClientInterceptor {
/**
* Intercept a service call to CreateSchedule
*/
create?: (input: CreateScheduleInput, next: Next<this, 'create'>) => Promise<CreateScheduleOutput>;
}

/**
* Input for {@link ScheduleClientInterceptor.create}
*
* @experimental
*/
export interface CreateScheduleInput {
readonly headers: Headers;
readonly options: CompiledScheduleOptions;
}

export type CreateScheduleOutput = {
readonly conflictToken: Uint8Array;
};

/**
* Interceptors for any high-level SDK client.
*
* NOTE: Currently only for {@link WorkflowClient}. More will be added later as needed.
* NOTE: Currently only for {@link WorkflowClient} and {@link ScheduleClient}. More will be added later as needed.
*/
export interface ClientInterceptors {
workflow?: WorkflowClientInterceptors;

/**
* @experimental
*/
schedule?: ScheduleClientInterceptor[];
}
Loading

0 comments on commit 808e562

Please sign in to comment.