devsisters / shardcake

Sharding and location transparency for Scala
https://devsisters.github.io/shardcake/
Apache License 2.0
395 stars 30 forks source link

[Feature Request] Graceful early termination without message timeout #102

Closed jgulotta closed 5 months ago

jgulotta commented 10 months ago

An entity may currently terminate itself early using ZIO.interrupt or be externally interrupted, but this comes at the expense of a SendTimeoutException eventually being issued for every message in the entity's queue before the queue shuts down. It would be nice to have at least one fail-fast/recovery mechanism that stops accepting new messages into the queue and allows processing of any remaining messages in the queue so that the senders do not have to wait the full timeout period.

Broad-strokes ideas for termination strategies:

It might be enough to have a single Sharding.terminateEntity[T](typ: EntityType[T], id: String, termination: TerminationStrategy[T]) style method, but perhaps specific methods like Sharding.terminateMessage[T](typ: EntityType[T], id: String, termination: T) and Sharding.terminateRemaining[T](typ: EntityType[T], id: String)(termination: Dequeue[T] => ZIO[...]) and variants make sense

ghostdogpr commented 5 months ago

Done in https://github.com/devsisters/shardcake/pull/103