microsoft / microsoft/durabletask-java
Improved orchestrator and activity input/output handling
Personne n'a encore pris cette issue.
- Langage dominant
- Java
- Étoiles
- 29
- Forks
- 18
- Merge moyen
- 1 j 10 h
- PR mergées (30 j)
- 2
Description
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:
- 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. - The call to
ctx.getInput()isn't intuitive, making the programming model harder for developers to learn. - 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.
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par examiner les interfaces TaskOrchestration et TaskActivity ainsi que les exemples de tests d’intégration référencés dans l’issue. Suivez la manière dont les entrées et les sorties circulent actuellement via le contexte, puis mettez à jour le modèle de programmation afin que les implémentations reçoivent des entrées typées et renvoient des sorties comme indiqué ; les tests d’intégration doivent démontrer l’utilisation proposée.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- java
- Domaine
- backend-api-design
- Type d'issue
- Fonctionnalité
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 35/100