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

Entity execution is not working from JavaScript orchestration #504

Closed cgillum closed 1 year ago

cgillum commented 1 year ago

Migrated from https://github.com/Azure/azure-functions-durable-extension/discussions/2436

Originally posted by **sibircevs** April 5, 2023 Hi, I would like to have a counter which will be unique for a particular customer. Entity must get and update the legacy system. Orchestration part: ``` const entityId = new df.EntityId("outgoingPaymentCounter", clientId); const paymentCounter = yield context.df.callEntity(entityId, "add", clientId); ``` Entity: ``` module.exports = df.entity(async function (context) { var currentValue = context.df.getState(() => 0); var updateOperation = ''; switch (context.df.operationName) { case "add": const clientId = context.df.getInput(); context.log(`[outgoingPaymentCounter] clientId = '${clientId}'`); try { const resultArr = await getCounter(context, clientId); currentValue = resultArr[0]; updateOperation = resultArr[1]; currentValue++; await saveCounter(context, clientId, currentValue, updateOperation); } catch (e) { context.log.error(`[outgoingPaymentCounter] entity error: ${e.message}`); break; } context.df.setState(currentValue); context.df.return(currentValue); break; } context.df.setState(currentValue); }); async function getCounter(context, clientId) { get the value from the legacy system }; async function saveCounter(context, clientId, currentValue, updateOperation) { save the value into the legacy system }; ``` Error: ``` 2023-04-05T14:15:06Z [Error] @outgoingpaymentcounter@LV120303-20311: Function 'outgoingpaymentcounter (Entity)' failed with an error. Reason: Internal error: System.ArgumentException: Out of proc orchestrators must return a valid JSON schema. ---> Microsoft.Azure.WebJobs.Script.Workers.WorkerProcessExitException: node exited with code 1 (0x1) ---> System.Exception: LanguageWorkerConsoleLog[error] Worker 9e32e034-106a-4e78-8abd-52150123b151 uncaught exception (learn more: https://go.microsoft.com/fwlink/?linkid=2097909 ): Error: Unable to get client data. Environment setup problem. at getCounter (/home/site/wwwroot/outgoingPaymentCounter/index.js:61:15) at Entity.fn (/home/site/wwwroot/outgoingPaymentCounter/index.js:17:35) at Entity. (/home/site/wwwroot/node_modules/durable-functions/lib/src/entity.js:37:48) at Generator.next () at /home/site/wwwroot/node_modules/durable-functions/lib/src/entity.js:8:71 at new Promise () at __awaiter (/home/site/wwwroot/node_modules/durable-functions/lib/src/entity.js:4:12) at Entity.handle (/home/site/wwwroot/node_modules/durable-functions/lib/src/entity.js:25:16) at Object. (/home/site/wwwroot/node_modules/durable-functions/lib/src/shim.js:24:15) at Generator.next () --- End of inner exception stack trace --- at Microsoft.Azure.WebJobs.Script.Description.WorkerFunctionInvoker.InvokeCore(Object[] parameters, FunctionInvocationContext context) in /src/azure-functions-host/src/WebJobs.Script/Description/Workers/WorkerFunctionInvoker.cs:line 96 at Microsoft.Azure.WebJobs.Script.Description.FunctionInvokerBase.Invoke(Object[] parameters) in /src/azure-functions-host/src/WebJobs.Script/Description/FunctionInvokerBase.cs:line 82 at Microsoft.Azure.WebJobs.Script.Description.FunctionGenerator.Coerce[T](Task`1 src) in /src/azure-functions-host/src/WebJobs.Script/Description/FunctionGenerator.cs:line 225 at Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`2.InvokeAsync(Object instance, Object[] arguments) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionInvoker.cs:line 52 at Microsoft.Azure.WebJobs.Extensions.DurableTask.TaskEntityShim.ExecuteOutOfProcBatch() in D:\a\_work\1\s\src\WebJobs.Extensions.DurableTask\Listener\TaskEntityShim.cs:line 526 --- End of inner exception stack trace --- at Microsoft.Azure.WebJobs.Extensions.DurableTask.TaskEntityShim.ExecuteOutOfProcBatch() in D:\a\_work\1\s\src\WebJobs.Extensions.DurableTask\Listener\TaskEntityShim.cs:line 532 at Microsoft.Azure.WebJobs.Extensions.DurableTask.TaskEntityShim.<>c__DisplayClass42_0.<g__ExecuteOperationsInBatch|0>d.MoveNext() in D:\a\_work\1\s\src\WebJobs.Extensions.DurableTask\Listener\TaskEntityShim.cs:line 282 --- End of stack trace from previous location --- at Microsoft.Azure.WebJobs.Extensions.DurableTask.TaskEntityShim.ExecuteBatch(CancellationToken onHostStopping) in D:\a\_work\1\s\src\WebJobs.Extensions.DurableTask\Listener\TaskEntityShim.cs:line 327 at Microsoft.Azure.WebJobs.Extensions.DurableTask.DurableTaskExtension.<>c__DisplayClass81_0.<b__0>d.MoveNext() in D:\a\_work\1\s\src\WebJobs.Extensions.DurableTask\DurableTaskExtension.cs:line 1045. IsReplay: False. State: Failed. HubName: funcindexopemdev001. AppName: func-indexo-pem-dev-001. SlotName: Production. ExtensionVersion: 2.9.1. SequenceNumber: 8. TaskEventId: -1 2023-04-05T14:15:06Z [Error] Executed 'Functions.outgoingPaymentCounter' (Failed, Id=4b34f87b-1f31-4b37-af59-5d35934e2c43, Duration=60ms) ```
cgillum commented 1 year ago

@sibircevs can you provide more details? The following will be required:

ghost commented 1 year ago

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

sibircevs commented 1 year ago

@cgillum

Hi, I'm sorry for the late response. I modified async functions getCounter and saveCounter and the problem disappeared. Now, I am not aware of what exactly was fixed. I guess, you can close this issue.

cgillum commented 1 year ago

@sibircevs glad to hear you got it working, though it’s too bad we don’t understand the root cause. I’ll close this for now but @davidmrdavid may want to take a look in case there might be a bug we should fix in the SDK.