哪一种适合完整的工作流程设计 Temporal 或 Cadence

时间:2021-05-14 11:11:42

标签: cadence-workflow cadence temporal-workflow

我想设计一个完整的端到端工作流编排引擎。

它有以下要求

  1. 线性工作流程
  2. 并行工作流 - 我想并行执行 n 个活动。在验证了我想要的所有活动的结果之后 继续下一个状态,否则工作流会失败
  3. 批量 - 假设我有 30 项活动要完成,但我希望以批量方式完成。就像如果窗口大小是 5 那么我想要 一次执行 5 个活动 T. 执行完所有活动后 并验证结果将继续进行或使工作流程失败。
  4. 循环 - 想要无限地运行活动直到满足某些条件
  5. 子工作流程
  6. 投票

1 个答案:

答案 0 :(得分:0)

Cadence 工作流程很容易支持所有 1-5。我不确定您所说的 Polling 是什么意思。如果您能提供更多详细信息,我会更新此答案以帮助您。

这是sample to execute activities in Leaner+parallel/batch+loop

  @Override
  public long calculate(long a, long b, long c) {
    LOGGER.info("workflow start...");

    long result = 0;

    // Async.invoke takes method reference and activity parameters and returns Promise.
    Promise<Long> ab = Async.function(activities::multiple, a, b);
    Promise<Long> ac = Async.function(activities::multiple, a, c);
    Promise<Long> bc = Async.function(activities::multiple, b, c);

    // Promise#get blocks until result is ready.
    this.abPlusAcPlusBc = result = ab.get() + ac.get() + bc.get();

    // waiting 30s for a human input to decide the factor N for g(n), based on a*b+a*c+b*c
    // the waiting timer is durable, independent of workers' liveness
    final boolean received = Workflow.await(Duration.ofMinutes(2), () -> this.factorForGn > 1);
    if (!received) {
      this.factorForGn = 10;
    }

    long fi_1 = 0; // f(0)
    long fi_2 = 1; // f(1)
    this.currentG = 1; // current g = f(0)*f(0) + f(1)*f(1)
    long i = 2;

    for (; i < this.factorForGn; i++) {
      // get next fibonacci number
      long fi = fi_1 + fi_2;
      fi_2 = fi_1;
      fi_1 = fi;

      this.currentG += activities.multiple(fi, fi);
    }

    result += this.currentG;
    return result;
  }

这是sample of using ChildWorkflow

相关问题