I have written a pseudo code for 2 version. I need to deploy version 2 with below constraints
- Skip order creation step
- Wait for notification if it has more than 24 hours to cancel
- Send the notification if it is less than or equal to 24 hours window and wait for cancellation
Can some one help in explaining how to deploy the new version and how to modify all the existing workflow instances to new version?
Version 1
- Create order
- Wait for auto cancellation duration if the order is pending
/* Version 1: Auto cancellation */
public void execute(byte [] orderRequest) {
order = create(Workflow.getInfo().getWorkflowId(), orderRequest);
Workflow.await(getAutoCancellationDuration(), () -> !this.order.getStatus().equals("PENDING"));
switch (this.order.getStatus()) {
case "PENDING":
this.order.setStatus("CANCELLED");
logger.info("order {} auto cancellation triggered", order.getId());
//triggerAutoCancellationWorkflow
break;
case "CANCELLED":
logger.info("order {} manual cancellation triggered", order.getId());
//triggerManualCancellationWorkflow
break;
case "APPROVED":
logger.info("order {} approval triggered", order.getId());
//triggerApprovalWorkflow
break;
}
Workflow.await(getArchiveDuration(), () -> this.order.getStatus().equals("ARCHIVE"));
}
Version 2
- Create order
- Trigger an email before 24hrs of cancellation
- Wait for auto cancellation duration if the order is pending
/* Version 2: Prior notification prior before auto cancellation */
public void execute(byte [] orderRequest) {
order = create(Workflow.getInfo().getWorkflowId(), orderRequest);
Workflow.await(getAutoCancellationDuration()-24hrs, () -> !this.order.getStatus().equals("PENDING"));
if(this.order.getStatus().equals("PENDING")) {
sendNotification();
}
Workflow.await(currentTime+24hrs, () -> !this.order.getStatus().equals("PENDING"));
switch (this.order.getStatus()) {
case "PENDING":
this.order.setStatus("CANCELLED");
logger.info("order {} auto cancellation triggered", order.getId());
//triggerAutoCancellationWorkflow
break;
case "CANCELLED":
logger.info("order {} manual cancellation triggered", order.getId());
//triggerManualCancellationWorkflow
break;
case "APPROVED":
logger.info("order {} approval triggered", order.getId());
//triggerApprovalWorkflow
break;
}
Workflow.await(getArchiveDuration(), () -> this.order.getStatus().equals("ARCHIVE"));
}