Skip to content

Commit

Permalink
Add EXT_START/END_OBS events when submitted via http
Browse files Browse the repository at this point in the history
  • Loading branch information
cquiroz committed Nov 20, 2023
1 parent f35bbfa commit 80b1652
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import java.util.logging.Logger
trait ObservationFSM[F[_]] {
def addObservationEvent(obsEvent: ObservationEvent): F[Unit]
def stopObservation: F[Unit]
def startObservation: F[Unit]
def step: F[Unit]
}

Expand Down Expand Up @@ -58,13 +59,17 @@ object ObservationFSM {
)
}.flatten

def stopObservation: F[Unit] = state.modify {
case Running(events) =>
WaitingForEvents(events, retryConfig.retries) -> (logger.infoF(
s"Observation $dataLabel stopped by Seqexeq"
) >> qStep)
case st @ _ => st -> F.unit
}.flatten
def startObservation: F[Unit] = addObservationEvent(ObservationEvent.EXT_START_OBS)

def stopObservation: F[Unit] =
addObservationEvent(ObservationEvent.EXT_END_OBS) *>
state.modify {
case Running(events) =>
WaitingForEvents(events, retryConfig.retries) -> (logger.infoF(
s"Observation $dataLabel stopped by Seqexeq"
) >> qStep)
case st @ _ => st -> F.unit
}.flatten

def step: F[Unit] = state.modify {
case st @ WaitingForEvents(_, _) => st -> waitForEvents
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ object ObservationManager {
def process(stateEvent: ObservationStateEvent): F[Unit] = {
println(stateEvent)
stateEvent match {
case Start(dataLabel, _) =>
case Start(dataLabel) =>
for {
_ <- logger.infoF(s"Starting observation $dataLabel")
_ <- addDataLabel(dataLabel)
i <- addDataLabel(dataLabel)
_ <- i.fsm.startObservation
} yield ()

case e @ Stop(dataLabel) => withObsItem(dataLabel, e)(_.fsm.stopObservation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import edu.gemini.aspen.giapi.data.{ DataLabel, ObservationEvent }
sealed trait ObservationStateEvent

object ObservationStateEvent {
final case class Start(dataLabel: DataLabel, programId: String) extends ObservationStateEvent
final case class Start(dataLabel: DataLabel) extends ObservationStateEvent
final case class Stop(dataLabel: DataLabel) extends ObservationStateEvent
final case class Abort(dataLabel: DataLabel) extends ObservationStateEvent
final case class Delete(dataLabel: DataLabel) extends ObservationStateEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ private[seqexec] final case class KeywordRequest(
)

private[seqexec] final case class OpenObservationRequest(
programId: String,
dataLabel: DataLabel,
keywords: List[KeywordValue]
)
Expand Down Expand Up @@ -53,10 +52,9 @@ object Decoders {
new Decoder[OpenObservationRequest] {
final def apply(c: HCursor): Decoder.Result[OpenObservationRequest] =
for {
pi <- c.downField("program_id").as[String]
dl <- c.downField("data_label").as[DataLabel]
kws <- c.downField("keywords").as[List[KeywordValue]]
} yield OpenObservationRequest(pi, dl, kws)
} yield OpenObservationRequest(dl, kws)
}

implicit val dataLabelRqstDecoder: Decoder[DataLabelRequest] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ object SeqexecServer {
for {
oor <- req.as[OpenObservationRequest]
_ <-
obsStateQ.offer(Start(oor.dataLabel, oor.programId))
obsStateQ.offer(Start(oor.dataLabel))
_ <- oor.keywords.traverse { kw =>
obsStateQ.offer(AddKeyword(oor.dataLabel, kwv2Collected(kw)))
}
Expand Down

0 comments on commit 80b1652

Please sign in to comment.