Skip to content

Commit

Permalink
feat: Add new schedule API
Browse files Browse the repository at this point in the history
  • Loading branch information
mjameswh committed Oct 26, 2022
1 parent 2146b14 commit 21ae0d7
Show file tree
Hide file tree
Showing 7 changed files with 2,183 additions and 1 deletion.
12 changes: 12 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,10 @@ 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 Workflows
*/
public readonly schedule: ScheduleClient;

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

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

/**
Expand Down
35 changes: 34 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,43 @@ export interface WorkflowClientInterceptors {
calls?: WorkflowClientCallsInterceptorFactory[];
}

export interface ScheduleClientCallsInterceptor {
/**
* Intercept a service call to CreateSchedule
*/
create?: (input: CreateScheduleInput, next: Next<this, 'create'>) => Promise<Uint8Array /* conflictToken */>;
}

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

interface ScheduleClientCallsInterceptorFactoryInput {
scheduleId: string;
}

/**
* A function that takes a {@link ScheduleClientCallsInterceptorFactoryInput} and returns an interceptor
*/
export interface ScheduleClientCallsInterceptorFactory {
(input: ScheduleClientCallsInterceptorFactoryInput): ScheduleClientCallsInterceptor;
}

/**
* A mapping of interceptor type of a list of factory functions
*/
export interface ScheduleClientInterceptors {
calls?: ScheduleClientCallsInterceptorFactory[];
}

/**
* 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;
schedule?: ScheduleClientInterceptors;
}
Loading

0 comments on commit 21ae0d7

Please sign in to comment.