Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/npm_and_yarn/modules/web/client/f…
Browse files Browse the repository at this point in the history
…ortawesome/pro-duotone-svg-icons-6.6.0
  • Loading branch information
cquiroz authored Nov 6, 2024
2 parents 100f5b8 + 139b46f commit 06e1e50
Show file tree
Hide file tree
Showing 58 changed files with 2,509 additions and 3,556 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ jobs:
timeout-minutes: 60
steps:
- name: Install sbt
if: contains(runner.os, 'macos')
run: brew install sbt
uses: sbt/setup-sbt@v1

- name: Checkout current branch (full)
uses: actions/checkout@v4
Expand Down Expand Up @@ -108,13 +107,16 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
scala: [3.5.0]
scala: [3.5.2]
java: [temurin@17]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (fast)
uses: actions/checkout@v4

- name: Setup SBT
uses: sbt/setup-sbt@v1

- name: Setup Java (temurin@17)
id: setup-java-temurin-17
if: matrix.java == 'temurin@17'
Expand Down
10 changes: 8 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ lazy val dockerHubLogin =
name = Some("Login to Docker Hub")
)

lazy val setupSbt = WorkflowStep.Use(
UseRef.Public("sbt", "setup-sbt", "v1"),
name = Some("Setup SBT")
)

lazy val sbtDockerPublish =
WorkflowStep.Sbt(
List("deploy/docker:publish"),
Expand All @@ -96,6 +101,7 @@ ThisBuild / githubWorkflowAddedJobs +=
"deploy",
"Build and publish Docker image / Deploy to Heroku",
WorkflowStep.Checkout ::
setupSbt ::
WorkflowStep.SetupJava(githubWorkflowJavaVersions.value.toList.take(1)) :::
setupNodeNpmInstall :::
dockerHubLogin ::
Expand All @@ -111,8 +117,8 @@ ThisBuild / lucumaCssExts += "svg"

Global / onChangedBuildSource := ReloadOnSourceChanges
ThisBuild / scalafixDependencies += "edu.gemini" % "lucuma-schemas_3" % LibraryVersions.lucumaSchemas
ThisBuild / scalaVersion := "3.5.0"
ThisBuild / crossScalaVersions := Seq("3.5.0")
ThisBuild / scalaVersion := "3.5.2"
ThisBuild / crossScalaVersions := Seq("3.5.2")
ThisBuild / scalacOptions ++= Seq("-language:implicitConversions")
ThisBuild / scalafixResolvers += coursierapi.MavenRepository.of(
"https://s01.oss.sonatype.org/content/repositories/snapshots/"
Expand Down
24 changes: 12 additions & 12 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 2 additions & 30 deletions modules/engine/src/main/scala/observe/engine/Engine.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,39 +51,14 @@ class Engine[F[_]: MonadThrow: Logger, S, U] private (
{
putS(id)(
Sequence.State.status.replace(SequenceState.Running.Init)(
seq.skips.getOrElse(seq).rollback
seq.rollback
)
) *>
send(Event.executing(id))
}.whenA(seq.status.isIdle || seq.status.isError)
case None => unit
}

/**
* startFrom starts a sequence from an arbitrary step. It does it by marking all previous steps to
* be skipped and then modifying the state sequence as if it was run. If the requested step is
* already run or marked to be skipped, the sequence will start from the next runnable step
*/
def startFrom(id: Observation.Id, step: Step.Id): HandleType[Unit] =
getS(id).flatMap {
case Some(seq)
if (seq.status.isIdle || seq.status.isError) && seq.toSequence.steps.exists(
_.id === step
) =>
val steps = seq.toSequence.steps
.takeWhile(_.id =!= step)
.mapFilter(p => (!p.status.isFinished).option(p.id))
val withSkips = steps.foldLeft[Sequence.State[F]](seq) { case (s, i) =>
s.setSkipMark(i, v = true)
}
putS(id)(
Sequence.State.status.replace(SequenceState.Running.Init)(
withSkips.skips.getOrElse(withSkips).rollback
)
) *> send(Event.executing(id))
case _ => unit
}

def pause(id: Observation.Id): HandleType[Unit] =
modifyS(id)(Sequence.State.userStopSet(true))

Expand Down Expand Up @@ -181,7 +156,7 @@ class Engine[F[_]: MonadThrow: Logger, S, U] private (
// Final State
case Some(qs: Sequence.State.Final[F]) =>
putS(id)(qs) *> switch(id)(
SequenceState.Running(userStop, internalStop, true)
SequenceState.Running(userStop, internalStop, waitingNextAtom = true)
) *> send(modifyState(atomLoad(this, id)))
// Execution completed. Check breakpoint here
case Some(qs) =>
Expand Down Expand Up @@ -405,9 +380,6 @@ class Engine[F[_]: MonadThrow: Logger, S, U] private (
case Breakpoints(id, _, step, v) =>
debug(s"Engine: breakpoints changed for sequence $id and step $step to $v") *>
modifyS(id)(_.setBreakpoints(step, v)) *> pure(UserCommandResponse(ue, Outcome.Ok, None))
case SkipMark(id, _, step, v) =>
debug(s"Engine: skip mark changed for sequence $id and step $step to $v") *>
modifyS(id)(_.setSkipMark(step, v)) *> pure(UserCommandResponse(ue, Outcome.Ok, None))
case Poll(_) =>
debug("Engine: Polling current state") *> pure(UserCommandResponse(ue, Outcome.Ok, None))
case GetState(f) => getState(f) *> pure(UserCommandResponse(ue, Outcome.Ok, None))
Expand Down
70 changes: 22 additions & 48 deletions modules/engine/src/main/scala/observe/engine/EngineStep.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package observe.engine
import cats.syntax.all.*
import lucuma.core.enums.Breakpoint
import lucuma.core.model.sequence.Step
import lucuma.core.util.NewType
import monocle.Focus
import monocle.Iso
import monocle.Lens
Expand All @@ -20,18 +19,11 @@ import observe.model.StepState
case class EngineStep[F[_]](
id: Step.Id,
breakpoint: Breakpoint,
skipped: EngineStep.Skipped,
skipMark: EngineStep.SkipMark,
executions: List[ParallelActions[F]]
)

object EngineStep {

object SkipMark extends NewType[Boolean]
type SkipMark = SkipMark.Type
object Skipped extends NewType[Boolean]
type Skipped = Skipped.Type

def isoBool: Iso[Breakpoint, Boolean] =
Iso[Breakpoint, Boolean](_ === Breakpoint.Enabled)(b =>
if (b) Breakpoint.Enabled else Breakpoint.Disabled
Expand All @@ -40,44 +32,34 @@ object EngineStep {
def breakpointL[F[_]]: Lens[EngineStep[F], Boolean] =
Focus[EngineStep[F]](_.breakpoint).andThen(isoBool)

def skippedL[F[_]]: Lens[EngineStep[F], Boolean] =
Focus[EngineStep[F]](_.skipped).andThen(Skipped.value)

def init[F[_]](id: Step.Id, executions: List[ParallelActions[F]]): EngineStep[F] =
EngineStep(id = id,
breakpoint = Breakpoint.Disabled,
skipped = Skipped(false),
skipMark = SkipMark(false),
executions = executions
)
EngineStep(id = id, breakpoint = Breakpoint.Disabled, executions = executions)

/**
* Calculate the `Step` `Status` based on the underlying `Action`s.
*/
private def status_[F[_]](step: EngineStep[F]): StepState =
if (step.skipped.value) StepState.Skipped
else
// Find an error in the Step
step.executions
.flatMap(_.toList)
.find(Action.errored)
.flatMap { x =>
x.state.runState match {
case ActionState.Failed(Result.Error(msg)) => msg.some
case _ => None
// Return error or continue with the rest of the checks
}
// Find an error in the Step
step.executions
.flatMap(_.toList)
.find(Action.errored)
.flatMap { x =>
x.state.runState match {
case ActionState.Failed(Result.Error(msg)) => msg.some
case _ => None
// Return error or continue with the rest of the checks
}
.map[StepState](StepState.Failed.apply)
.getOrElse(
// All actions in this Step were completed successfully, or the Step is empty.
if (step.executions.flatMap(_.toList).exists(Action.aborted)) StepState.Aborted
else if (step.executions.flatMap(_.toList).forall(Action.completed)) StepState.Completed
else if (step.executions.flatMap(_.toList).forall(_.state.runState.isIdle))
StepState.Pending
// Not all actions are completed or pending.
else StepState.Running
)
}
.map[StepState](StepState.Failed.apply)
.getOrElse(
// All actions in this Step were completed successfully, or the Step is empty.
if (step.executions.flatMap(_.toList).exists(Action.aborted)) StepState.Aborted
else if (step.executions.flatMap(_.toList).forall(Action.completed)) StepState.Completed
else if (step.executions.flatMap(_.toList).forall(_.state.runState.isIdle))
StepState.Pending
// Not all actions are completed or pending.
else StepState.Running
)

extension [F[_]](s: EngineStep[F]) {
def status: StepState = EngineStep.status_(s)
Expand All @@ -89,7 +71,6 @@ object EngineStep {
case class Zipper[F[_]](
id: Step.Id,
breakpoint: Breakpoint,
skipMark: SkipMark,
pending: List[ParallelActions[F]],
focus: Execution[F],
done: List[ParallelActions[F]],
Expand Down Expand Up @@ -121,9 +102,7 @@ object EngineStep {
*/
val uncurrentify: Option[EngineStep[F]] =
if (pending.isEmpty)
focus.uncurrentify.map(x =>
EngineStep(id, breakpoint, Skipped(false), skipMark, x.prepend(done))
)
focus.uncurrentify.map(x => EngineStep(id, breakpoint, x.prepend(done)))
else None

/**
Expand All @@ -134,13 +113,9 @@ object EngineStep {
EngineStep(
id = id,
breakpoint = breakpoint,
skipped = Skipped(false),
skipMark = skipMark,
executions = done ++ focus.toParallelActionsList ++ pending
)

val skip: EngineStep[F] = toStep.copy(skipped = Skipped(true))

def update(executions: List[ParallelActions[F]]): Zipper[F] =
Zipper
.calcRolledback(executions)
Expand Down Expand Up @@ -175,7 +150,6 @@ object EngineStep {
Zipper(
step.id,
step.breakpoint,
step.skipMark,
exes,
x,
Nil,
Expand Down
6 changes: 0 additions & 6 deletions modules/engine/src/main/scala/observe/engine/Event.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ object Event {
steps: List[Step.Id],
v: Breakpoint
): Event[F, S, U] = EventUser[F, S, U](Breakpoints(id, user.some, steps, v))
def skip[F[_], S, U](
id: Observation.Id,
user: User,
step: Step.Id,
v: Boolean
): Event[F, S, U] = EventUser[F, S, U](SkipMark(id, user.some, step, v))
def poll[F[_], S, U](clientId: ClientId): Event[F, S, U] =
EventUser[F, S, U](Poll(clientId))
def getState[F[_], S, U](f: S => Option[Stream[F, Event[F, S, U]]]): Event[F, S, U] =
Expand Down
Loading

0 comments on commit 06e1e50

Please sign in to comment.