Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Supervision.restart for SubFlow's #981

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -512,13 +512,6 @@ import pekko.util.ccompat.JavaConverters._
private var substreamWaitingToBePushed = false
private var substreamCancelled = false

def propagateSubstreamCancel(ex: Throwable): Boolean =
decider(ex) match {
case Supervision.Stop => true
case Supervision.Resume => false
case Supervision.Restart => false
}

override def onPull(): Unit = {
if (substreamSource eq null) {
// can be already pulled from substream in case split after
Expand Down Expand Up @@ -610,14 +603,31 @@ import pekko.util.ccompat.JavaConverters._

override def onDownstreamFinish(cause: Throwable): Unit = {
substreamCancelled = true
if (isClosed(in) || propagateSubstreamCancel(cause)) {
cancelStage(cause)
} else {
// Start draining
if (!hasBeenPulled(in)) pull(in)
decider(cause) match {
case Supervision.Stop =>
cancelStage(cause)
case Supervision.Resume =>
if (isClosed(in)) cancelStage(cause)
else {
// Start draining
if (!hasBeenPulled(in)) pull(in)
}
case Supervision.Restart =>
if (isClosed(in)) completeStage()
else {
restartState()
// Start draining
if (!hasBeenPulled(in)) pull(in)
}
}
}

private def restartState(): Unit = {
substreamSource = null
substreamWaitingToBePushed = false
substreamCancelled = false
}

override def onPush(): Unit = {
val elem = grab(in)
try {
Expand All @@ -638,9 +648,15 @@ import pekko.util.ccompat.JavaConverters._
} catch {
case NonFatal(ex) =>
decider(ex) match {
case Supervision.Resume => pull(in)
case Supervision.Stop => onUpstreamFailure(ex)
case Supervision.Restart => onUpstreamFailure(ex) // TODO implement restart?
case Supervision.Resume => pull(in)
case Supervision.Stop => onUpstreamFailure(ex)
case Supervision.Restart =>
if (isClosed(in)) completeStage()
else {
restartState()
// Start draining
if (!hasBeenPulled(in)) pull(in)
}
}
}
}
Expand Down
Loading