Skip to content

Commit

Permalink
EDU-2293: updated to rethrow exception in Workflow fail case
Browse files Browse the repository at this point in the history
  • Loading branch information
fairlydurable committed May 2, 2024
1 parent 80c4add commit 6d81a01
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
30 changes: 30 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
## make -f ../Makefile
## make run -f ../Makefile
## make worker -f ../Makefile

.PHONY: build notests clean worker run serve servedb stop

build:
@mvn clean install -Dorg.slf4j.simpleLogger.defaultLogLevel=info 2>/dev/null

notests:
@mvn clean install -DskipTests -Dorg.slf4j.simpleLogger.defaultLogLevel=info 2>/dev/null

clean:
@mvn clean -q -Dmaven.logging.level=0

worker:
@mvn compile exec:java -Dexec.mainClass="moneytransferapp.MoneyTransferWorker" -Dorg.slf4j.simpleLogger.defaultLogLevel=warn

run:
@mvn compile exec:java -Dexec.mainClass="moneytransferapp.TransferApp" -Dorg.slf4j.simpleLogger.defaultLogLevel=warn

serve:
@nohup `command -v temporal` server start-dev --log-level=never &

servedb:
`command -v temporal` server start-dev --log-level=never --db-filename=/Users/ericasadun/Desktop/temporal.db

stop:
@pkill temporal

8 changes: 4 additions & 4 deletions src/main/java/moneytransfer/MoneyTransferWorkflowImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ public void transfer(TransactionDetails transaction) {
// A recovery mechanism can fail too. Handle any exception
System.out.printf("[%s] Deposit of $%d to account %s failed. Did not compensate withdrawal.\n",
transactionReferenceId, amountToTransfer, destinationAccountId);
System.out.printf("[%s] Workflow failed.", transactionReferenceId);
System.out.flush();
}

System.out.printf("[%s] Ended transaction in inconsistent state.\n",
transactionReferenceId);
System.out.flush();
// Rethrowing the exception causes a Workflow Task failure
throw(e);
}
}
}
// @@@SNIPEND
2 changes: 1 addition & 1 deletion src/main/java/moneytransfer/TransferApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static void main(String[] args) throws Exception {
System.out.printf("\nMONEY TRANSFER PROJECT\n\n");
System.out.printf("Initiating transfer of $%d from [Account %s] to [Account %s].\n\n",
amountToTransfer, fromAccount, toAccount);
System.out.printf("[WorkflowID: %s]\n[RunID: %s]\n\n", we.getWorkflowId(), we.getRunId());
System.out.printf("[WorkflowID: %s]\n[RunID: %s]\n[Transaction Reference: %s]\n\n", we.getWorkflowId(), we.getRunId(), referenceId);
System.exit(0);
}
}
Expand Down
Binary file added workflow_input.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6d81a01

Please sign in to comment.