DurableOrchestrationContext Class

Context of the durable orchestration execution.

Parameter data for orchestration bindings that can be used to schedule function-based activities.

Inheritance
builtins.object
DurableOrchestrationContext

Constructor

DurableOrchestrationContext(history: List[Dict[Any, Any]], instanceId: str, isReplaying: bool, parentInstanceId: str, input: Any = None, **kwargs)

Parameters

history
Required
instanceId
Required
isReplaying
Required
parentInstanceId
Required
input
default value: None

Methods

call_activity

Schedule an activity for execution.

call_activity_with_retry

Schedule an activity for execution with retry options.

call_http

Schedule a durable HTTP call to the specified endpoint.

call_sub_orchestrator

Schedule sub-orchestration function named name for execution.

call_sub_orchestrator_with_retry

Schedule sub-orchestration function named name for execution, with retry-options.

continue_as_new

Schedule the orchestrator to continue as new.

create_timer

Create a Durable Timer Task to implement a deadline at which to wake-up the orchestrator.

from_json

Convert the value passed into a new instance of the class.

get_input

Get the orchestration input.

new_uuid

Create a new UUID that is safe for replay within an orchestration or operation.

The default implementation of this method creates a name-based UUID using the algorithm from RFC 4122 §4.3. The name input used to generate this value is a combination of the orchestration instance ID and an internally managed sequence number.

set_custom_status

Set the customized orchestration status for your orchestrator function.

This status is also returned by the orchestration client through the get_status API

task_all

Schedule the execution of all activities.

Similar to Promise.all. When called with yield or return, returns an array containing the results of all [[Task]]s passed to it. It returns when all of the [[Task]] instances have completed.

Throws an exception if any of the activities fails :param activities: List of activities to schedule :type activities: <xref:azure.durable_functions.List[Task]>

task_any

Schedule the execution of all activities.

Similar to Promise.race. When called with yield or return, returns the first [[Task]] instance to complete.

Throws an exception if all of the activities fail

wait_for_external_event

Wait asynchronously for an event to be raised with the name name.

call_activity

Schedule an activity for execution.

call_activity(name: str, input_: Any | None = None) -> Task

Parameters

name
str
Required

The name of the activity function to call.

input
<xref:Optional>[<xref:Any>]
Required

The JSON-serializable input to pass to the activity function.

input_
default value: None

Returns

A Durable Task that completes when the called activity function completes or fails.

Return type

call_activity_with_retry

Schedule an activity for execution with retry options.

call_activity_with_retry(name: str, retry_options: RetryOptions, input_: Any | None = None) -> Task

Parameters

name
str
Required

The name of the activity function to call.

retry_options
RetryOptions
Required

The retry options for the activity function.

input
<xref:Optional>[<xref:Any>]
Required

The JSON-serializable input to pass to the activity function.

input_
default value: None

Returns

A Durable Task that completes when the called activity function completes or fails completely.

Return type

call_http

Schedule a durable HTTP call to the specified endpoint.

call_http(method: str, uri: str, content: str | None = None, headers: Dict[str, str] | None = None, token_source: TokenSource = None) -> Task

Parameters

method
str
Required

The HTTP request method.

uri
str
Required

The HTTP request uri.

content
<xref:Optional>[str]
default value: None

The HTTP request content.

headers
<xref:Optional>[<xref:Dict>[str, str]]
default value: None

The HTTP request headers.

token_source
<xref:azure.durable_functions.TokenSource>
default value: None

The source of OAuth token to add to the request.

Returns

The durable HTTP request to schedule.

Return type

call_sub_orchestrator

Schedule sub-orchestration function named name for execution.

call_sub_orchestrator(name: str, input_: Any | None = None, instance_id: str | None = None) -> Task

Parameters

name
str
Required

The name of the orchestrator function to call.

input
<xref:Optional>[<xref:Any>]
Required

The JSON-serializable input to pass to the orchestrator function.

instance_id
<xref:Optional>[str]
default value: None

A unique ID to use for the sub-orchestration instance.

input_
default value: None

Returns

A Durable Task that completes when the called sub-orchestrator completes or fails.

Return type

call_sub_orchestrator_with_retry

Schedule sub-orchestration function named name for execution, with retry-options.

call_sub_orchestrator_with_retry(name: str, retry_options: RetryOptions, input_: Any | None = None, instance_id: str | None = None) -> Task

Parameters

name
str
Required

The name of the activity function to schedule.

retry_options
RetryOptions
Required

The settings for retrying this sub-orchestrator in case of a failure.

input
<xref:Optional>[<xref:Any>]
Required

The JSON-serializable input to pass to the activity function. Defaults to None.

instance_id
str
default value: None

The instance ID of the sub-orchestrator to call.

input_
default value: None

Returns

A Durable Task that completes when the called sub-orchestrator completes or fails.

Return type

continue_as_new

Schedule the orchestrator to continue as new.

continue_as_new(input_: Any)

Parameters

input
Any
Required

The new starting input to the orchestrator.

input_
Required

create_timer

Create a Durable Timer Task to implement a deadline at which to wake-up the orchestrator.

create_timer(fire_at: datetime) -> Task

Parameters

fire_at
datetime
Required

The time for the timer to trigger

Returns

A Durable Timer Task that schedules the timer to wake up the activity

Return type

from_json

Convert the value passed into a new instance of the class.

from_json(json_string: str)

Parameters

json_string
str
Required

Context passed a JSON serializable value to be converted into an instance of the class

Returns

New instance of the durable orchestration context class

Return type

get_input

Get the orchestration input.

get_input() -> Any | None

new_uuid

Create a new UUID that is safe for replay within an orchestration or operation.

The default implementation of this method creates a name-based UUID using the algorithm from RFC 4122 §4.3. The name input used to generate this value is a combination of the orchestration instance ID and an internally managed sequence number.

new_uuid() -> str

Returns

New UUID that is safe for replay within an orchestration or operation.

Return type

str

set_custom_status

Set the customized orchestration status for your orchestrator function.

This status is also returned by the orchestration client through the get_status API

set_custom_status(status: Any)

Parameters

status
str
Required

Customized status provided by the orchestrator

task_all

Schedule the execution of all activities.

Similar to Promise.all. When called with yield or return, returns an array containing the results of all [[Task]]s passed to it. It returns when all of the [[Task]] instances have completed.

Throws an exception if any of the activities fails :param activities: List of activities to schedule :type activities: <xref:azure.durable_functions.List[Task]>

task_all(activities: List[Task]) -> TaskSet

Parameters

activities
Required

Returns

The results of all activities.

Return type

task_any

Schedule the execution of all activities.

Similar to Promise.race. When called with yield or return, returns the first [[Task]] instance to complete.

Throws an exception if all of the activities fail

task_any(activities: List[Task]) -> TaskSet

Parameters

activities
<xref:List>[<xref:Task>]
Required

List of activities to schedule

Returns

The first [[Task]] instance to complete.

Return type

wait_for_external_event

Wait asynchronously for an event to be raised with the name name.

wait_for_external_event(name: str) -> Task

Parameters

name
str
Required

The event name of the event that the task is waiting for.

Returns

Task to wait for the event

Return type

Attributes

current_utc_datetime

Get the current date/time.

This date/time value is derived from the orchestration history. It always returns the same value at specific points in the orchestrator function code, making it deterministic and safe for replay.

Returns

The current date/time in a way that is safe for use by orchestrator functions

Return type

<xref:azure.durable_functions.datetime>

custom_status

Get customized status of current orchestration.

function_context

Get the function level attributes not used by durable orchestrator.

Returns

Object containing function level attributes not used by durable orchestrator.

Return type

histories

Get running history of tasks that have been scheduled.

instance_id

Get the ID of the current orchestration instance.

The instance ID is generated and fixed when the orchestrator function is scheduled. It can be either auto-generated, in which case it is formatted as a GUID, or it can be user-specified with any format.

Returns

The ID of the current orchestration instance.

Return type

str

is_replaying

Get the value indicating orchestration replaying itself.

This property is useful when there is logic that needs to run only when the orchestrator function is not replaying. For example, certain types of application logging may become too noisy when duplicated as part of orchestrator function replay. The orchestrator code could check to see whether the function is being replayed and then issue the log statements when this value is false.

Returns

Value indicating whether the orchestrator function is currently replaying.

Return type

parent_instance_id

Get the ID of the parent orchestration.

The parent instance ID is generated and fixed when the parent orchestrator function is scheduled. It can be either auto-generated, in which case it is formatted as a GUID, or it can be user-specified with any format.

Returns

ID of the parent orchestration of the current sub-orchestration instance

Return type

str

will_continue_as_new

Return true if continue_as_new was called.