-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): add server status tracking and prevent doing certain operat…
…ions if the server status endpoint does not return success
- Loading branch information
updraft0
committed
Jun 12, 2024
1 parent
42619cf
commit 3b58e13
Showing
16 changed files
with
170 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
server/src/main/scala/org/updraft0/controltower/server/map/MapReactive.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
server/src/main/scala/org/updraft0/controltower/server/tracking/ServerStatusTracker.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.updraft0.controltower.server.tracking | ||
|
||
import org.updraft0.controltower.server.Log | ||
import org.updraft0.esi.client.{EsiClient, EsiError, ServerStatusResponse} | ||
import zio.* | ||
|
||
trait ServerStatusTracker: | ||
def status: UIO[Either[EsiError, ServerStatusResponse]] | ||
|
||
object ServerStatusTracker: | ||
type Env = EsiClient | ||
|
||
// Every poll interval, update status | ||
private val PollInterval = 30.seconds | ||
|
||
def layer: ZLayer[Env, Nothing, ServerStatusTracker] = ZLayer.scoped(apply()) | ||
|
||
def apply(): ZIO[Scope & Env, Nothing, ServerStatusTracker] = | ||
for | ||
ref <- Ref.make[Either[EsiError, ServerStatusResponse]]( | ||
Left(EsiError.ServiceUnavailable("Internal tracker error")) | ||
) | ||
// refresh once | ||
_ <- doRefresh(ref) | ||
// fork in background | ||
_ <- (doRefresh(ref) | ||
.repeat(Schedule.once.andThen(Schedule.fixed(PollInterval))) | ||
.ignoreLogged @@ Log.BackgroundOperation("statusTracker")).forkScoped | ||
yield new ServerStatusTracker: | ||
override def status: UIO[Either[EsiError, ServerStatusResponse]] = ref.get | ||
|
||
private def doRefresh(ref: Ref[Either[EsiError, ServerStatusResponse]]) = | ||
ZIO | ||
.serviceWithZIO[EsiClient](_.getServerStatus(()).either) | ||
.flatMap(ref.set(_)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.