microsoft / microsoft/durabletask-java

Improved orchestrator and activity input/output handling

Aperta
#15 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
Java
Stelle
29
Fork
18
Merge medio
1g 10h
PR unite (30g)
2

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia esaminando le interfacce TaskOrchestration e TaskActivity e gli esempi di test di integrazione a cui si fa riferimento nella issue. Traccia il modo in cui input e output fluiscono attualmente attraverso il contesto, quindi aggiorna il modello di programmazione in modo che le implementazioni ricevano input tipizzati e restituiscano output come mostrato; i test di integrazione dovrebbero dimostrare l’utilizzo proposto.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
java
Ambito
backend-api-design
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.