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

Detect and override hooks of the same kind #6842

Merged
merged 1 commit into from
May 29, 2023
Merged
Show file tree
Hide file tree
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 @@ -36,8 +36,9 @@ class ShutdownHookActivator[F[+_, +_]: Exec: CovariantFlatMap]
scheduled: List[UUID] = Nil
): Receive = {
case RegisterShutdownHook(projectId, hook) =>
val realHook = hook.asInstanceOf[ShutdownHook[F]]
val updated = hooks.updated(projectId, realHook :: hooks(projectId))
val realHook = hook.asInstanceOf[ShutdownHook[F]]
val uniqueHooks = hooks(projectId).filter(!_.isSameKind(realHook))
val updated = hooks.updated(projectId, realHook :: uniqueHooks)
context.become(running(updated, scheduled))

case ProjectClosed(projectId) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ trait ShutdownHook[F[+_, +_]] {
*/
def execute(): F[Nothing, Unit]

/** Checks if the provided `hook`` refers to the same kind of action as `this`` */
def isSameKind(hook: ShutdownHook[F]): Boolean

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,17 @@ class MoveProjectDirCmd[F[+_, +_]: CovariantFlatMap: ErrorChannel](
)
}

/** Returns the project ID to which this hook refers to */
def getProjectId(): UUID =
projectId

/** @inheritdoc */
override def isSameKind(hook: ShutdownHook[F]): Boolean = {
hook match {
case cmd: MoveProjectDirCmd[_] =>
projectId == cmd.getProjectId()
case _ =>
false
}
}
}