From af916d61f95df1d16397d02f972f5475122ec36e Mon Sep 17 00:00:00 2001 From: Hannah Hunter Date: Mon, 29 Jan 2024 10:47:03 -0500 Subject: [PATCH] add monitor pattern Signed-off-by: Hannah Hunter --- .../workflow/workflow-patterns.md | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/daprdocs/content/en/developing-applications/building-blocks/workflow/workflow-patterns.md b/daprdocs/content/en/developing-applications/building-blocks/workflow/workflow-patterns.md index 9749e2142..b91b81009 100644 --- a/daprdocs/content/en/developing-applications/building-blocks/workflow/workflow-patterns.md +++ b/daprdocs/content/en/developing-applications/building-blocks/workflow/workflow-patterns.md @@ -614,11 +614,28 @@ def send_alert(ctx, message: str): ```javascript +const statusMonitorWorkflow: TWorkflow = async function* (ctx: WorkflowContext): any { + let duration; + const status = yield ctx.callActivity(checkStatusActivity); + if (status === "healthy") { + // Check less frequently when in a healthy state + // set duration to 1 hour + duration = 60 * 60; + } else { + yield ctx.callActivity(alertActivity, "job unhealthy"); + // Check more frequently when in an unhealthy state + // set duration to 5 minutes + duration = 5 * 60; + } + // Put the workflow to sleep until the determined time + ctx.createTimer(duration); + + // Restart from the beginning with the updated state + ctx.continueAsNew(); + }; ``` -> This example assumes you have a predefined `MyEntityState` class with a boolean `IsHealthy` property. - {{% /codetab %}} {{% codetab %}}