vitaliihonta / zio-temporal

Build invincible apps with ZIO and https://temporal.io

Home Page:https://zio-temporal.vhonta.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Revisit error model

vitaliihonta opened this issue · comments

Either's are not retried by temporal. Only thrown exceptions are.
The only way ZIO errors can be retried is using ZIO.die, which looks strange

Here is a list of examples to verify the new zio-temporal error model on:

It's weird to have only ZIO.die trigger retries since ZIO will throw an error and kill the fiber generating an stack trace. I understand the retry mechanic could be part of the logic to better handle errors.

In the Java SDK, you can even filter which exceptions are filtered-out and I believe it's a good model: https://github.com/temporalio/samples-java/blob/cb78ebce84f7f3346bc0584282a34d06b21181f2/src/main/java/io/temporal/samples/hello/HelloActivityRetry.java#L110.

This way we could have retries on exceptions (whenever you return a ZIO failure) but could also filter ones that should not.

For example, failing with ZIO.die, generates the exception below until a success retry happens:

❯ scli zio-temporal-activity-retry.scala
SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See https://www.slf4j.org/codes.html#noProviders for further details.
timestamp=2023-03-21T09:34:56.46401-03:00  level=INFO thread=zio-fiber-7 message="Started sample-worker"
timestamp=2023-03-21T09:34:56.802524-03:00 level=INFO thread=zio-fiber-6 message="Will submit message "testMsg""
timestamp=2023-03-21T09:34:57.050257-03:00 level=DEBUG thread=zio-fiber-27 message="Received message: testMsg"
timestamp=2023-03-21T09:34:57.087042-03:00 level=DEBUG thread=zio-fiber-27 message="Fiber zio-fiber-27 did not handle an error" cause=Exception in thread "zio-fiber-27" java.lang.Exception: ACK: testMsg
	at EchoActivityImpl.eventuallyFail$$anonfun$3$$anonfun$2$$anonfun$1(zio-temporal-activity-retry.scala:47)
	at zio.ZIO$.die$$anonfun$1(ZIO.scala:3081)
	at zio.ZIO$.failCause$$anonfun$1$$anonfun$1$$anonfun$1(ZIO.scala:3155)
	at <empty>.EchoActivityImpl.eventuallyFail(zio-temporal-activity-retry.scala:47)
	at <empty>.EchoActivityImpl.eventuallyFail(zio-temporal-activity-retry.scala:51)
	at <empty>.EchoActivityImpl.echo(zio-temporal-activity-retry.scala:40)
	at zio.temporal.internal.ZioUnsafeFacade$.unsafeRunAsyncZIO.fiber.macro(ZioUnsafeFacade.scala:28)
timestamp=2023-03-21T09:34:58.022766-03:00 level=DEBUG thread=zio-fiber-28 message="Received message: testMsg"
timestamp=2023-03-21T09:34:58.024072-03:00 level=DEBUG thread=zio-fiber-28 message="Fiber zio-fiber-28 did not handle an error" cause=Exception in thread "zio-fiber-28" java.lang.Exception: ACK: testMsg
	at EchoActivityImpl.eventuallyFail$$anonfun$3$$anonfun$2$$anonfun$1(zio-temporal-activity-retry.scala:47)
	at zio.ZIO$.die$$anonfun$1(ZIO.scala:3081)
	at zio.ZIO$.failCause$$anonfun$1$$anonfun$1$$anonfun$1(ZIO.scala:3155)
	at <empty>.EchoActivityImpl.eventuallyFail(zio-temporal-activity-retry.scala:47)
	at <empty>.EchoActivityImpl.eventuallyFail(zio-temporal-activity-retry.scala:51)
	at <empty>.EchoActivityImpl.echo(zio-temporal-activity-retry.scala:40)
	at zio.temporal.internal.ZioUnsafeFacade$.unsafeRunAsyncZIO.fiber.macro(ZioUnsafeFacade.scala:28)
timestamp=2023-03-21T09:34:59.021626-03:00 level=DEBUG thread=zio-fiber-29 message="Received message: testMsg"
timestamp=2023-03-21T09:34:59.022999-03:00 level=DEBUG thread=zio-fiber-29 message="Fiber zio-fiber-29 did not handle an error" cause=Exception in thread "zio-fiber-29" java.lang.Exception: ACK: testMsg
	at EchoActivityImpl.eventuallyFail$$anonfun$3$$anonfun$2$$anonfun$1(zio-temporal-activity-retry.scala:47)
	at zio.ZIO$.die$$anonfun$1(ZIO.scala:3081)
	at zio.ZIO$.failCause$$anonfun$1$$anonfun$1$$anonfun$1(ZIO.scala:3155)
	at <empty>.EchoActivityImpl.eventuallyFail(zio-temporal-activity-retry.scala:47)
	at <empty>.EchoActivityImpl.eventuallyFail(zio-temporal-activity-retry.scala:51)
	at <empty>.EchoActivityImpl.echo(zio-temporal-activity-retry.scala:40)
	at zio.temporal.internal.ZioUnsafeFacade$.unsafeRunAsyncZIO.fiber.macro(ZioUnsafeFacade.scala:28)
timestamp=2023-03-21T09:35:00.231454-03:00 level=DEBUG thread=zio-fiber-30 message="Received message: testMsg"
timestamp=2023-03-21T09:35:00.319188-03:00 level=INFO thread=zio-fiber-6 message="The workflow result: {value=ACK: testMsg, left=false, right=true}"

@oridag I've finally managed to release the new error model, feel free to try it out!
I appreciate any feedback 😄

Nice! I'll be sure to give it a try soon!