Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions packages/client/src/schedule-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export class ScheduleClient extends BaseClient {
scheduleId: opts.scheduleId,
schedule: {
spec: encodeScheduleSpec(opts.spec),
action: await encodeScheduleAction(this.dataConverter, opts.action, headers),
action: await encodeScheduleAction(this.dataConverter, this.options.namespace, opts.action, headers),
policies: encodeSchedulePolicies(opts.policies),
state: encodeScheduleState(opts.state),
},
Expand Down Expand Up @@ -298,7 +298,7 @@ export class ScheduleClient extends BaseClient {
scheduleId,
schedule: {
spec: encodeScheduleSpec(opts.spec),
action: await encodeScheduleAction(this.dataConverter, opts.action, header),
action: await encodeScheduleAction(this.dataConverter, this.options.namespace, opts.action, header),
policies: encodeSchedulePolicies(opts.policies),
state: encodeScheduleState(opts.state),
},
Expand Down Expand Up @@ -432,7 +432,11 @@ export class ScheduleClient extends BaseClient {
return {
scheduleId,
spec: decodeScheduleSpec(raw.schedule.spec),
action: await decodeScheduleAction(this.client.dataConverter, raw.schedule.action),
action: await decodeScheduleAction(
this.client.dataConverter,
this.client.options.namespace,
raw.schedule.action
),
memo: await decodeMapFromPayloads(this.client.dataConverter, raw.memo?.fields),
searchAttributes: decodeSearchAttributes(raw.searchAttributes?.indexedFields),
typedSearchAttributes: decodeTypedSearchAttributes(raw.searchAttributes?.indexedFields),
Expand Down
36 changes: 30 additions & 6 deletions packages/client/src/schedule-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
extractWorkflowType,
LoadedDataConverter,
} from '@temporalio/common';
import { withSerializationContext } from '@temporalio/common/lib/converter/serialization-context';
import { encodeUserMetadata, decodeUserMetadata } from '@temporalio/common/lib/internal-non-workflow/codec-helpers';
import {
encodeUnifiedSearchAttributes,
Expand Down Expand Up @@ -245,18 +246,32 @@ export function encodeScheduleSpec(spec: ScheduleSpec): temporal.api.schedule.v1
};
}

function dataConverterWithWorkflowContext(
dataConverter: LoadedDataConverter,
namespace: string,
workflowId: string
): LoadedDataConverter {
return withSerializationContext(dataConverter, {
type: 'workflow',
namespace,
workflowId,
});
}

export async function encodeScheduleAction(
dataConverter: LoadedDataConverter,
namespace: string,
action: CompiledScheduleAction,
headers: Headers
): Promise<temporal.api.schedule.v1.IScheduleAction> {
const workflowDataConverter = dataConverterWithWorkflowContext(dataConverter, namespace, action.workflowId);
return {
startWorkflow: {
workflowId: action.workflowId,
workflowType: {
name: action.workflowType,
},
input: { payloads: await encodeToPayloads(dataConverter, ...action.args) },
input: { payloads: await encodeToPayloads(workflowDataConverter, ...action.args) },
taskQueue: {
kind: temporal.api.enums.v1.TaskQueueKind.TASK_QUEUE_KIND_NORMAL,
name: action.taskQueue,
Expand All @@ -265,15 +280,15 @@ export async function encodeScheduleAction(
workflowRunTimeout: msOptionalToTs(action.workflowRunTimeout),
workflowTaskTimeout: msOptionalToTs(action.workflowTaskTimeout),
retryPolicy: action.retry ? compileRetryPolicy(action.retry) : undefined,
memo: action.memo ? { fields: await encodeMapToPayloads(dataConverter, action.memo) } : undefined,
memo: action.memo ? { fields: await encodeMapToPayloads(workflowDataConverter, action.memo) } : undefined,
searchAttributes:
action.searchAttributes || action.typedSearchAttributes // eslint-disable-line @typescript-eslint/no-deprecated
? {
indexedFields: encodeUnifiedSearchAttributes(action.searchAttributes, action.typedSearchAttributes), // eslint-disable-line @typescript-eslint/no-deprecated
}
: undefined,
header: { fields: headers },
userMetadata: await encodeUserMetadata(dataConverter, action.staticSummary, action.staticDetails),
userMetadata: await encodeUserMetadata(workflowDataConverter, action.staticSummary, action.staticDetails),
priority: action.priority ? compilePriority(action.priority) : undefined,
},
};
Expand Down Expand Up @@ -321,10 +336,19 @@ export function decodeScheduleSpec(pb: temporal.api.schedule.v1.IScheduleSpec):

export async function decodeScheduleAction(
dataConverter: LoadedDataConverter,
namespace: string,
pb: temporal.api.schedule.v1.IScheduleAction
): Promise<ScheduleDescriptionAction> {
if (pb.startWorkflow) {
const { staticSummary, staticDetails } = await decodeUserMetadata(dataConverter, pb.startWorkflow?.userMetadata);
const workflowDataConverter = dataConverterWithWorkflowContext(
dataConverter,
namespace,
pb.startWorkflow.workflowId!
);
const { staticSummary, staticDetails } = await decodeUserMetadata(
workflowDataConverter,
pb.startWorkflow?.userMetadata
);
return {
type: 'startWorkflow',

Expand All @@ -333,8 +357,8 @@ export async function decodeScheduleAction(
workflowType: pb.startWorkflow.workflowType!.name!,

taskQueue: pb.startWorkflow.taskQueue!.name!,
args: await decodeArrayFromPayloads(dataConverter, pb.startWorkflow.input?.payloads),
memo: await decodeMapFromPayloads(dataConverter, pb.startWorkflow.memo?.fields),
args: await decodeArrayFromPayloads(workflowDataConverter, pb.startWorkflow.input?.payloads),
memo: await decodeMapFromPayloads(workflowDataConverter, pb.startWorkflow.memo?.fields),
retry: decompileRetryPolicy(pb.startWorkflow.retryPolicy),
searchAttributes: decodeSearchAttributes(pb.startWorkflow.searchAttributes?.indexedFields),
typedSearchAttributes: decodeTypedSearchAttributes(pb.startWorkflow.searchAttributes?.indexedFields),
Expand Down
Loading
Loading