Azure / azure-functions-durable-js

JavaScript library for using the Durable Functions bindings
https://www.npmjs.com/package/durable-functions
MIT License
128 stars 46 forks source link

`continueAsNew` cannot be yielded #371

Open jnsvd opened 2 years ago

jnsvd commented 2 years ago

Describe the bug According to the documentation, to implement an eternal orchestration, one needs to include the following statement:

yield context.df.continueAsNew(undefined);

This leads to an exception Orchestration yielded data of type undefined. Only Task types can be yielded.Please refactor your orchestration to yield only Tasks.. When removing yield, i.e. change the statement into context.df.continueAsNew(undefined);, behavior looks correct.

Investigative information

To Reproduce Steps to reproduce the behavior:

  1. Create an eternal orchestrator:
    
    const df = require("durable-functions");
    const moment = require("moment");

module.exports = df.orchestrator(function*(context){ const result = yield context.df.callActivity("AnActivity");

context.log(Result: ${result});

const wait = moment.utc(context.df.currentUtcDateTime).add(5, "s"); yield context.df.createTimer(wait.toDate());

yield context.df.continueAsNew(undefined); });


2. Create the activity `AnActivity` that is called from the orchestrator:
```javascript
module.exports = function (context) {
  return "someResult";
}
  1. Create a starter function for the eternal orchestrator:
    
    const df = require("durable-functions");

module.exports = async function (context, req) { const client = df.getClient(context); const instanceId = "InstanceId"; await client.startNew(req.params.functionName, instanceId, null);

return client.createCheckStatusResponse(context.bindingData.req, instanceId); };


4. Start the functions runtime locally: `func host start`
5. Start the eternal orchestrator: `curl -X POST http://localhost:7071/api/orchestrators/EternalOrchestrator`

**Expected behavior**
Orchestrator function keeps running indefinitely without errors.

**Actual behavior**
Orchestrator function crashes when encountering `yield context.df.continueAsNew(undefined);` with error:

[2022-06-23T10:02:25.135Z] InstanceId: Function 'EternalOrchestrator (Orchestrator)' failed with an error. Reason: Message: Orchestration yielded data of type undefined. Only Task types can be yielded.Please refactor your orchestration to yield only Tasks., StackTrace: at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) [2022-06-23T10:02:25.135Z] at System.Threading.Tasks.Task1.GetResultCore(Boolean waitCompletionNotification) [2022-06-23T10:02:25.136Z] at System.Threading.Tasks.Task1.get_Result() [2022-06-23T10:02:25.136Z] at Microsoft.Azure.WebJobs.Extensions.DurableTask.TaskOrchestrationShim.InvokeUserCodeAndHandleResults(RegisteredFunctionInfo orchestratorInfo, OrchestrationContext innerContext) in D:\a_work\1\s\src\WebJobs.Extensions.DurableTask\Listener\TaskOrchestrationShim.cs:line 150. IsReplay: False. State: Failed. HubName: TestHubName. AppName: . SlotName: . ExtensionVersion: 2.7.1. SequenceNumber: 12. TaskEventId: -1 [2022-06-23T10:02:25.146Z] Executed 'Functions.EternalOrchestrator' (Failed, Id=38ceb138-6aa1-411f-b443-f6e6f0ba3694, Duration=39ms) [2022-06-23T10:02:25.146Z] System.Private.CoreLib: Exception while executing function: Functions.EternalOrchestrator. Microsoft.Azure.WebJobs.Extensions.DurableTask: Orchestrator function 'EternalOrchestrator' failed: Orchestration yielded data of type undefined. Only Task types can be yielded.Please refactor your orchestration to yield only Tasks. ^C[2022-06-23T10:02:27.559Z] Language Worker Process exited. Pid=84184. [2022-06-23T10:02:27.559Z] node exited with code 130 (0x82). .



**Known workarounds**
Remove `yield` keyword when calling `context.df.continueAsNew`.
cgillum commented 2 years ago

This was a change made in the 2.0.0 release of the npm package. It looks like the documentation hasn’t been updated to reflect this change. The examples you’re referring to were for the 1.x versions of this npm module.

FYI: @davidmrdavid @lilyjma

davidmrdavid commented 2 years ago

Thanks for reaching out @jnsvd: @cgillum is right, this was one of the breaking changes in the v2 release of the DF NodeJS SDK. It appears we need to take a closer look at our docs to update this guidance, thanks for the report.

You can read our list of breaking changes here: https://github.com/Azure/azure-functions-durable-js/releases/tag/2.0.0

I'm assigning this ticket to myself so I follow-up with the documentation update work.