Skip to content

Commit b4e2efe

Browse files
Merge pull request #266339 from nytian/nytian/update_suspend
Update suspend-resume samples
2 parents 2645799 + 26e291e commit b4e2efe

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed

articles/azure-functions/durable/durable-functions-instance-management.md

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -712,13 +712,11 @@ public static async Task Run(
712712
[DurableClient] IDurableOrchestrationClient client,
713713
[QueueTrigger("suspend-resume-queue")] string instanceId)
714714
{
715+
// To suspend an orchestration
715716
string suspendReason = "Need to pause workflow";
716717
await client.SuspendAsync(instanceId, suspendReason);
717718

718-
// Wait for 30 seconds to ensure that the orchestrator state is updated to suspended.
719-
DateTime dueTime = context.CurrentUtcDateTime.AddSeconds(30);
720-
await context.CreateTimer(dueTime, CancellationToken.None);
721-
719+
// To resume an orchestration
722720
string resumeReason = "Continue workflow";
723721
await client.ResumeAsync(instanceId, resumeReason);
724722
}
@@ -732,13 +730,11 @@ const df = require("durable-functions");
732730
module.exports = async function(context, instanceId) {
733731
const client = df.getClient(context);
734732

733+
// To suspend an orchestration
735734
const suspendReason = "Need to pause workflow";
736735
await client.suspend(instanceId, suspendReason);
737736

738-
// Wait for 30 seconds to ensure that the orchestrator state is updated to suspended.
739-
const deadline = DateTime.fromJSDate(context.df.currentUtcDateTime, {zone: 'utc'}).plus({ seconds: 30 });
740-
yield context.df.createTimer(deadline.toJSDate());
741-
737+
// To resume an orchestration
742738
const resumeReason = "Continue workflow";
743739
await client.resume(instanceId, resumeReason);
744740
};
@@ -754,13 +750,11 @@ from datetime import timedelta
754750
async def main(req: func.HttpRequest, starter: str, instance_id: str):
755751
client = df.DurableOrchestrationClient(starter)
756752

753+
# To suspend an orchestration
757754
suspend_reason = "Need to pause workflow"
758755
await client.suspend(instance_id, suspend_reason)
759756

760-
# Wait for 30 seconds to ensure that the orchestrator state is updated to suspended.
761-
due_time = context.current_utc_datetime + timedelta(seconds=30)
762-
yield context.create_timer(due_time)
763-
757+
# To resume an orchestration
764758
resume_reason = "Continue workflow"
765759
await client.resume(instance_id, resume_reason)
766760
```
@@ -770,20 +764,20 @@ async def main(req: func.HttpRequest, starter: str, instance_id: str):
770764
```powershell
771765
param($Request, $TriggerMetadata)
772766
773-
# Get instance id from body
774767
$InstanceId = $Request.Body.InstanceId
775-
$SuspendReason = 'Need to pause workflow'
776768
769+
# To suspend an orchestration
770+
$SuspendReason = 'Need to pause workflow'
777771
Suspend-DurableOrchestration -InstanceId $InstanceId -Reason $SuspendReason
778772
779-
# Wait for 30 seconds to ensure that the orchestrator state is updated to suspended.
780-
$duration = New-TimeSpan -Seconds 30
781-
Start-DurableTimer -Duration $duration
782-
773+
# To resume an orchestration
783774
$ResumeReason = 'Continue workflow'
784775
Resume-DurableOrchestration -InstanceId $InstanceId -Reason $ResumeReason
785776
```
786777

778+
> [!NOTE]
779+
> This change applies only to the standalone [Durable Functions PowerShell SDK](https://www.powershellgallery.com/packages/AzureFunctions.PowerShell.Durable.SDK), which is currently [in preview](durable-functions-powershell-v2-sdk-migration-guide.md).
780+
787781
# [Java](#tab/java)
788782

789783
```java
@@ -793,14 +787,14 @@ public void suspendResumeInstance(
793787
@DurableClientInput(name = "durableContext") DurableClientContext durableContext) {
794788
String instanceID = req.getBody();
795789
DurableTaskClient client = durableContext.getClient();
790+
791+
// To suspend an orchestration
796792
String suspendReason = "Need to pause workflow";
797793
client.suspendInstance(instanceID, suspendReason);
798794

799-
// Wait for 30 seconds to ensure that the orchestrator state is updated to suspended.
800-
ctx.createTimer(Duration.ofSeconds(30)).await();
801-
795+
// To resume an orchestration
802796
String resumeReason = "Continue workflow";
803-
client.getClient().resumeInstance(instanceID, resumeReason);
797+
client.resumeInstance(instanceID, resumeReason);
804798
}
805799
```
806800

0 commit comments

Comments
 (0)