dhiaayachi / temporal

Temporal service
https://docs.temporal.io
MIT License
0 stars 0 forks source link

Sending signal using batch request gives error in workflow #362

Open dhiaayachi opened 2 weeks ago

dhiaayachi commented 2 weeks ago

Issue

We are using typescript sdk to send a signal (with args) to a list of workflows using batch operation. The worker is setup with the default data convertor/default settings. When the signal is received by the workflow we get an error.

Error

{
  "message": "Unknown encoding: binary/protobuf",
  "source": "TypeScriptSDK",
  "stackTrace": "/app/workflow-bundle-5feb3d484fc78c2a5e62.js:4067\n            throw new errors_1.ValueError(`Unknown encoding: ${encoding}`);\n            ^\n\nValueError: Unknown encoding: binary/protobuf\n    at DefaultPayloadConverter.fromPayload (/app/node_modules/@temporalio/common/src/converter/payload-converter.ts:163:12)\n    at /app/node_modules/@temporalio/common/src/converter/payload-converter.ts:84:54\n    at Array.map (<anonymous>)\n    at arrayFromPayloads (/app/node_modules/@temporalio/common/src/converter/payload-converter.ts:84:18)\n    at Activator.signalWorkflow (/app/node_modules/@temporalio/workflow/src/internals.ts:545:30)\n    at /app/node_modules/@temporalio/workflow/src/worker-interface.ts:215:29\n    at Object.activate (/app/node_modules/@temporalio/workflow/src/worker-interface.ts:221:2)\n    at evalmachine.<anonymous>:1:18",
  "encodedAttributes": null,
  "cause": null
}

Stack Trace

/app/workflow-bundle-5feb3d484fc78c2a5e62.js:4067
            throw new errors_1.ValueError(Unknown encoding: ${encoding});
            ^
ValueError: Unknown encoding: binary/protobuf
    at DefaultPayloadConverter.fromPayload (/app/node_modules/@temporalio/common/src/converter/payload-converter.ts:163:12)
    at /app/node_modules/@temporalio/common/src/converter/payload-converter.ts:84:54
    at Array.map (<anonymous>)
    at arrayFromPayloads (/app/node_modules/@temporalio/common/src/converter/payload-converter.ts:84:18)
    at Activator.signalWorkflow (/app/node_modules/@temporalio/workflow/src/internals.ts:545:30)
    at /app/node_modules/@temporalio/workflow/src/worker-interface.ts:215:29
    at Object.activate (/app/node_modules/@temporalio/workflow/src/worker-interface.ts:221:2)
    at evalmachine.<anonymous>:1:18

Sample signal args received by workflow

[
  {
    "metadata": {
      "encoding": "YmluYXJ5L3Byb3RvYnVm",
      "messageType": "dGVtcG9yYWwuYXBpLmNvbW1vbi52MS5QYXlsb2Fkcw==",
      "encodingDecoded": "binary/protobuf"
    },
    "data": "ChwKFgoIZW5jb2RpbmcSCmpzb24vcGxhaW4SAnt9"
  }
]

Batch Request

export async function sendSignals(
  temporalClient: WorkflowClient,
  temporalWorkflowIds: string[],
  signalDef: string,
  args: any,
  reason: string,
) {
  const batchOperationRequest: temporal.api.workflowservice.v1.IStartBatchOperationRequest = {
    namespace: TEMPORAL_NAMESPACE,
    jobId: randomUUID(),
    reason,
    signalOperation: {
      input: {
        payloads: [{ etag: args["etag"], isDefault: args["isDefault"] }].map((arg) =>
          temporalClient.options.loadedDataConverter.payloadConverter.toPayload(arg),
        ),
      },
      signal: signalDef,
    },
    executions: temporalWorkflowIds.map((id) => ({ workflowId: id })),
  };
  await temporalClient.workflowService.startBatchOperation(batchOperationRequest);
}

Expected

That the signal args should be correctly received by the workflow when sending a signal using batch operation.

dhiaayachi commented 1 day ago

Thanks for reporting this issue!

The error you are seeing is due to the fact that the TypeScript SDK does not support binary/protobuf encoding by default. You have two options to resolve this:

By implementing one of these options, you will ensure that the data is correctly encoded and decoded, resolving the error and allowing your signals to be received by the workflow.