Hi Team,
Kindly let me know if there are any best practices to design a Lifecycle workflow.
As we have complex use cases to perform and the requirements can vary to the greater extent in the future as well. Can you please suggest a suitable design?
Basic requirements are,
- The lifecycle workflow must stay active until a successful completion and should not get closed on an event of any exceptions
- It performs a backup where it exports data from several different micro services and uploads it
- It performs a cleanup of data which involves calling several REST APIs.
Designing in the way as shown in the snippet below, brings in lot of complexities to maintain the code.
Are there any alternatives to the inner loops to perform retry of a block in case of failures?
Below snippet has backup step as a child workflow and methods to perform cleanup put in the main workflow,
Please advice on when to go for a child workflow vs code to be part of main workflow?
while (true) {
try {
if (state == null) {
state = State.ACTIVE;
// Wait for ever till mark for cleanup flag is set by a signal.
Workflow.await(() -> markedForCleanup || forceCleanup);
state = State.MARKED_FOR_CLEANUP;
}
// Perform Backup
while (true) {
// Trigger a backup child workflow
boolean backupResult = backupChildWF.execute(envKey);
if (backupResult) {
break;
} else {
Workflow.sleep(Duration.ofDays(DEFAULT_SLEEP_FOR_RETRY));
continue;
}
}
// Perform Cleanup
while (true) {
// This invokes activity methods within performCleanup
boolean performCleanup = performCleanup(envKey);
if (performCleanup) {
break;
} else {
Workflow.sleep(Duration.ofDays(DEFAULT_SLEEP_FOR_RETRY));
continue;
}
}
// All done, close the workflow
state = State.CLEANUP_COMPLETED;
return;
} catch (Exception e) {
state = State.ATTEMPT_RETRY;
continue;
}
}