I wanted to design a complete end-to-end workflow orchestration engine.
It has the following requirements
All 1-5 are supported easily in Cadence workflow. I am not sure what you mean by Polling
. If you can provide more details, I will update this answer to help you.
Here is the 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;
}
And this is the sample of using ChildWorkflow.