Skip to content

Adding Methods and Properties

Katy Shimizu edited this page Sep 10, 2019 · 1 revision

Adding Properties

Checklist

  • .NET Extension: modify binding information
  • Language Library: copy property to object

.NET Extension: modify binding information

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.

Trigger Bindings

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.

Bindings

Modify (or) add the converter method in DurableTaskExtension's IExtensionConfigProvider.Initialize implementation. See DurableOrchestrationClientToString for an example.

Attach property to JavaScript object

Assign the property from the binding information to the corresponding JavaScript/TypeScript object. Depending on the binding in question, this happens in:

Adding Methods

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:

  1. Add any necessary information to the binding (as above for properties)
  2. Implement the method in JavaScript to return the expected response
  3. Add new schema interpretation logic (if needed; see subsections)

DurableClient

Checklist

  • .NET Extension: add webhook template
  • Language Library: implement method

.NET Extension: add webhook template

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.

Language Library: implement 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.

DurableOrchestrationContext and DurableEntityContext

Checklist

  • .NET Extension: modify binding information (if needed)
  • Language Library: implement method
  • .NET Extension: add schema interpretation

.NET Extension: modify binding information (if needed)

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.

Language Library: implement method

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

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

DurableEntityContext methods should add operations to the operationBatch property of the EntityState object returned from the function.

.NET Extension: add schema interpretation

DurableOrchestrationContext

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 Actions goes.)

DurableEntityContext

Out-of-proc logic happens in the TaskEntityShim.ExecuteOutOfProcBatch method.