Skip to content
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

Improved orchestrator and activity input/output handling #15

Open
cgillum opened this issue Feb 1, 2022 · 0 comments
Open

Improved orchestrator and activity input/output handling #15

cgillum opened this issue Feb 1, 2022 · 0 comments

Comments

@cgillum
Copy link
Member

cgillum commented Feb 1, 2022

Background

The current TaskOrchestration and TaskActivity interfaces require implementations to use the context object to receive inputs. Consider the following example (copied from the integration tests):

final String orchestratorName = "SingleActivity";
final String activityName = "Echo";
final String input = Instant.now().toString();
DurableTaskGrpcWorker worker = this.createWorkerBuilder()
    .addOrchestrator(orchestratorName, ctx -> {
        String activityInput = ctx.getInput(String.class);
        String output = ctx.callActivity(activityName, activityInput, String.class).get();
        ctx.complete(output);
    })
    .addActivity(activityName, ctx -> {
        return String.format("Hello, %s!", ctx.getInput(String.class));
    })
    .buildAndStart();

This design, while it works, has a few issues:

  1. The fetching of inputs is not type-safe because the call to ctx.getInput(String.class) could fail if the input isn't actually a string.
  2. The call to ctx.getInput() isn't intuitive, making the programming model harder for developers to learn.
  3. The call to ctx.complete(output) is both unintuitive and inconsistent with how activity functions are defined.

This issue tracks improving the programming model to make processing inputs and outputs more intuitive and type-safe.

Proposal

The proposal is to change these interface definitions so that a developer could write the following, simpler orchestration and activity implementations:

final String orchestratorName = "SingleActivity";
final String activityName = "Echo";
final String input = Instant.now().toString();
DurableTaskGrpcWorker worker = this.createWorkerBuilder()
    .addOrchestrator(orchestratorName, (ctx, activityInput) -> {
        return ctx.callActivity(activityName, activityInput, String.class).get();
    })
    .addActivity(activityName, (ctx, name) -> {
        return String.format("Hello, %s!", name);
    })
    .buildAndStart();

The differences are:

  • The orchestrator and activity functions have the input passed to them explicitly.
  • The orchestrator can use the return value to set the output.

This results in a simpler, more intuitive programming model and is also consistent with the proposed C# programming model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant