New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for binding expressions in activity functions #172

Merged
merged 2 commits into from Mar 1, 2018

Conversation

Projects
None yet
2 participants
@cgillum
Collaborator

cgillum commented Feb 28, 2018

This PR fixes #123 (enable binding expressions in activity functions. it allows the function author to bind to the name of the parameter or to one of the top-level fields in the activity payload.

Example 1: Binding to the parameter name

This activity function takes a string argument (the name of a blob) and uses that value to bind to blob input and output bindings.

Activity Function

public static async Task ArchiveBlob(
    [ActivityTrigger] string name,
    [Blob("test/{name}", FileAccess.Read)] Stream input,
    [Blob("test/{name}-archive", FileAccess.Write)] Stream output)
{
    await input.CopyToAsync(output);
}

Orchestrator Function

public static async Task Orchestrator([OrchestrationTrigger] DurableOrchestrationContext ctx)
{
    string blobName = ctx.GetInput<string>();
    await ctx.CallActivityAsync("ArchiveBlob", blobName);
}

Example 2: Binding to the activity data payload

This activity function takes a custom POCO argument (it could also be a JSON argument) and uses the data contents to bind to blob inputs and outputs. Note the use of data in the binding expression, which always acts as a reference to the activity argument data.

Activity Function

public static async Task CopyBlob(
    [ActivityTrigger] JObject ignored,
    [Blob("test/{data.InputPrefix}-{data.Suffix}", FileAccess.Read)] Stream input,
    [Blob("test/{data.OutputPrefix}-{data.Suffix}", FileAccess.Write)] Stream output)
{
    await input.CopyToAsync(output);
}

Orchestrator Function

public static async Task Orchestrator([OrchestrationTrigger] DurableOrchestrationContext ctx)
{
    var data = new
    {
        InputPrefix = "Input",
        OutputPrefix = "Output",
        Suffix = 42,
    };

    await ctx.CallActivityAsync("CopyBlob", data);
}

Both of these examples are verified in the new unit tests that are included in this PR.

@cgillum cgillum requested review from MikeStall and kashimiz Feb 28, 2018

{
await host.StartAsync();
string connectionString = AmbientConnectionStringProvider.Instance.GetConnectionString(ConnectionStringNames.Storage);

This comment has been minimized.

@MikeStall

MikeStall Feb 28, 2018

FYI, we could simplify this test to avoid Blobs and be totally in-memory.
We have a short binding extension (you could copy from Azure/azure-webjobs-sdk#1513 ) that operates entirely in-memory.

@MikeStall

MikeStall Feb 28, 2018

FYI, we could simplify this test to avoid Blobs and be totally in-memory.
We have a short binding extension (you could copy from Azure/azure-webjobs-sdk#1513 ) that operates entirely in-memory.

This comment has been minimized.

@cgillum

cgillum Feb 28, 2018

Collaborator

Good to know. One thing I like about end-to-end tests, though, is that they sometimes make for good mini-samples.

@cgillum

cgillum Feb 28, 2018

Collaborator

Good to know. One thing I like about end-to-end tests, though, is that they sometimes make for good mini-samples.

@cgillum cgillum merged commit d33979a into dev Mar 1, 2018

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
license/cla All CLA requirements met.
Details

@cgillum cgillum deleted the binding-expressions branch Mar 1, 2018

cgillum added a commit that referenced this pull request Mar 2, 2018

Beta 3 release payload (#176)
* Sync Response feature for Orchestration Client  (#110)
* Support cross-language return values for orchestration triggers
* Introduced StyleCop and fixed related warnings.
* Fix warnings related to XML doc comment links
* Enabling unit testing using abstract base classes (#117)
* Fix multiple WaitForExternalEvent issue (#141) (#144)
* Replace Counter sample with Monitor sample. (#118)
* When parameter is null, convert to empty string. (#137, #148)
* Allow partition count to be set in host.json (#149)
* Query Orchestration History (#142)
* Make StartNewAsync return only when the instance has started running (#168)
* Small fix to make AsyncLock.cs faster and more robust.
* Replace Counter sample with Monitor sample. #118
* Fix query string parsing bug and add regression test (#171)
* Support for binding expressions in activity functions (#172)
* Added csx Monitor sample, removed csx Counter sample. (#173)
* Package updates for beta3 plus minor updates to README & samples (#175)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment