问题
In my activity function I am doing this
do {
await timeout(500);
} while (await getStatus() === false);
where,
function timeout(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
getStatus()
is a function that does a get
request to see if process in other service is complete or not and returns true
or false
based on this.
I need my activity function to wait before the process in other service is complete. But activity function execution by default is limited to 5 minutes.
my getStatus()
can take more than 2-3 hours or more based on different scenarios to return true
.
What can I do here? Any advice?
回答1:
You have a couple of options:
Option A: Use Monitor pattern + Rewind
Could you split out the getStatus
code to another Activity Function instead? If yes, then assume the following:
ActivityFunction_A
- contains code before the do-while loop that is polling withgetStatus()
ActivityFunction_B
- contains the code that polls forgetStatus
with maximum execution time of 10 minutes.ActivityFunction_C
- contains code after thegetStatus
returnsTRUE
You can now orchestrate the workflow sequence
ActivityFunction_A => ActivityFunction_B => ActivityFunction_C
using the Monitor pattern.
Since any one of the Activity Functions could fail or timeout and there are potential side-effects of executing each activity function, you should also use the Rewind feature (currently in preview) to rewind and replay only starting from the first failed Activity Function in the sequence.
Option B: Use App Service Plan
If your workflow does not really need to scale out to a lot of instances dynamically, you can migrate your Functions to an App Service Plan with AlwaysOn turned on.
来源:https://stackoverflow.com/questions/53864209/timeout-in-an-activity-function-of-azure-durable-functions