-
Notifications
You must be signed in to change notification settings - Fork 54
Adding Methods and Properties
- .NET Extension: modify binding information
- Language Library: copy property to object
Properties that are static for the lifetime of a function invocation, such as TaskHubName
or InstanceId
(cf. the dynamic CurrentUtcDateTime
), should be added to the binding information passed to the function at runtime.
Modify the corresponding ITriggerBinding.BindAsync
method to include the desired property. Out-of-proc functions accept a serialized JSON string. See the OrchestrationTriggerBinding
class for an example, referring to OrchestrationContextToString
method.
Note that not all properties available at a function's runtime are available at binding time! Be sure to test when your desired property is set. If it is the default value at binding time, you will need to alter the corresponding DurableTaskExtension.<BindingType>Middleware
method to set the property earlier in the invocation pipeline. Refer to the DurableTaskExtension.OrchestrationMiddleware
method for an example of these assignments.
Modify (or) add the converter method in DurableTaskExtension
's IExtensionConfigProvider.Initialize
implementation. See DurableOrchestrationClientToString
for an example.
Assign the property from the binding information to the corresponding JavaScript/TypeScript object. Depending on the binding in question, this happens in:
-
DurableClient
: constructor -
DurableOrchestrationContext
:handle
method -
DurableEntityContext
:handle
method
The process of adding methods to DurableClient
, DurableOrchestrationContext
, and DurableEntityContext
is much the same for all three binding objects, with some differences covered below. The general approach is:
- Add any necessary information to the binding (as above for properties)
- Implement the method in JavaScript to return the expected response
- Add new schema interpretation logic (if needed; see subsections)
- .NET Extension: add webhook template
- Language Library: implement method
Due to the limitations of output bindings in out-of-proc languages for Azure Functions, DurableClient
uses extension webhooks to replicate the behavior of the .NET DurableClient
. Webhook URIs are templated and passed via the durableClient
binding (as for properties) to the JavaScript function. Refer to HttpApiHandler.GetInstanceCreationLinks and HttpApiHandler.CreateHttpManagementPayload, which are called by the DurableOrchestrationClientToString binding converter method.
The corresponding method on the JavaScript DurableClient
replaces placeholders in the templated webhook URI, calls it, and parses the HTTP response, and returns the appropriate value for the result. Note that there are slight discrepancies between the behavior of the webhooks and the .NET DurableClient
methods (ex. exception-throwing) that should be watched and accounted for.
- .NET Extension: modify binding information (if needed)
- Language Library: implement method
- .NET Extension: add schema interpretation
Most DurableOrchestrationContext
methods make use of the HistoryEvent
array that comes from the Durable Task Framework, which has already been added to the .NET extension's binding logic. DurableEntityContext
makes use of the OperationBatch
array, which is likewise already in place. However, future methods may require additions.
The DurableOrchestrationContext
and DurableEntityContext
objects are created in JavaScript as part of the Orchestrator.handle
and Entity.handle
methods. Note that as part of the creation, <method>.bind(this, [args])
is used. This is so that the proper this
context is available when the method is called.
DurableOrchestrationContext
methods require a Task
to be returned (except in the case of timers), which is used by the Orchestrator.handle
method to determine the next action (ex. call context.done
, advance the generator). Methods use the HistoryEvent
array to determine the state of a requested action, and therefore what information to return as a Task
. An Action
should always be returned, regardless of whether the async work request represented by the method has completed or not. See the CallActivity
method for an example.
DurableEntityContext
methods should add operations to the operationBatch
property of the EntityState
object returned from the function.
Refer to the OutOfProcOrchestrationShim
in .NET. Note the AsyncActionType
enum (new methods will need to add to this) and the ProcessAsyncActions
method (this is where interpretation of JS Action
s goes.)
Out-of-proc logic happens in the TaskEntityShim.ExecuteOutOfProcBatch
method.