-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Further work on using RunnableStep (#90)
* Incorporate instrumentation in the RunnableStep * Working on the execution model * Fix build issue * Working on step tracing
- Loading branch information
1 parent
bbe052f
commit d89088a
Showing
22 changed files
with
361 additions
and
157 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package morphir.flowz | ||
|
||
sealed abstract class Flow[-SIn, +SOut, -P, -R, +E, +A] {} |
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,3 @@ | ||
package morphir.flowz | ||
|
||
object FlowArgs {} |
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,19 @@ | ||
package morphir.flowz | ||
|
||
import zio._ | ||
|
||
abstract class FlowExecutor[+InitialState, +Params, +R <: Has[_]] { | ||
|
||
/** | ||
* The environment used for executing a flow. | ||
*/ | ||
def environment: Layer[Nothing, R] | ||
|
||
/** | ||
* Initialize the execution of a flow given the initial environment. | ||
* Part of initializing a flow involves constructing the initial state and parameters for that flow. | ||
*/ | ||
def initialize: RIO[FlowInitEnv, (InitialState, Params)] | ||
} | ||
|
||
object FlowExecutor {} |
6 changes: 2 additions & 4 deletions
6
...phir/flowz/experimental/FlowSuccess.scala → ...flowz/src/morphir/flowz/FlowSuccess.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package morphir.flowz | ||
import morphir.flowz.instrumentation.InstrumentationEvent | ||
import zio.ZIO | ||
|
||
final case class RunnableStep[-SIn, +SOut, -Msg, -R, +E, +A]( | ||
override val label: Option[String], | ||
underlyingStep: Step[SIn, SOut, Msg, R, E, A] | ||
) extends Step[SIn, SOut, Msg, R with StepRuntimeEnv, E, A] { | ||
|
||
/** | ||
* Defines the underlying behavior of this `Step`. | ||
*/ | ||
protected[flowz] def behavior(state: SIn, message: Msg): ZIO[R with StepRuntimeEnv, E, StepSuccess[SOut, A]] = | ||
for { | ||
uid <- StepExecutionId.nextExecutionId | ||
labelResolved <- ZIO.succeed(label getOrElse "N/A") | ||
_ <- iLog.trace(InstrumentationEvent.stepExecutionStarted(uid, labelResolved)) | ||
result <- | ||
underlyingStep | ||
.behavior(state, message) | ||
.tapCause(cause => iLog.error(InstrumentationEvent.stepExecutionFailed(uid, labelResolved, cause), cause)) | ||
.tap(_ => iLog.trace(InstrumentationEvent.stepExecutionSucceeded(uid, labelResolved))) | ||
} yield result | ||
|
||
/** | ||
* Runs the step. | ||
*/ | ||
final def run(implicit ev1: Any <:< SIn, ev2: Any <:< Msg): ZIO[R with StepRuntimeEnv, E, StepSuccess[SOut, A]] = | ||
run((), ()) | ||
|
||
/** | ||
* Runs the step. | ||
*/ | ||
final def run(state: SIn, message: Msg): ZIO[R with StepRuntimeEnv, E, StepSuccess[SOut, A]] = | ||
behavior(state, message) | ||
|
||
/** | ||
* Runs the step. | ||
*/ | ||
final def run(message: Msg)(implicit ev: Any <:< SIn): ZIO[R with StepRuntimeEnv, E, StepSuccess[SOut, A]] = | ||
run((), message) | ||
|
||
/** | ||
* Runs the step. | ||
*/ | ||
final def runResult(implicit ev1: Any <:< SIn, ev2: Any <:< Msg): ZIO[R with StepRuntimeEnv, E, A] = | ||
run((), ()).map(_.result) | ||
} | ||
|
||
object RunnableStep { | ||
def step[SIn, SOut, Msg, R, Err, A]( | ||
label: String | ||
)(theStep: Step[SIn, SOut, Msg, R, Err, A]): RunnableStep[SIn, SOut, Msg, R, Err, A] = | ||
theStep match { | ||
case runnable @ RunnableStep(_, _) => runnable.asInstanceOf[RunnableStep[SIn, SOut, Msg, R, Err, A]] | ||
case _ => RunnableStep(Option(label), theStep) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package morphir.flowz | ||
|
||
trait StepAspect[-SIn, +SOut, -Msg, -R, +E, +A] { | ||
def apply[SIn1 <: SIn, SOut1 >: SOut, Msg1 <: Msg, R1 <: R, E1 >: E, A1 >: A]( | ||
step: Step[SIn1, SOut1, Msg1, R1, E1, A1] | ||
): Step[SIn1, SOut1, Msg1, R1, E1, A1] | ||
} | ||
|
||
object StepAspect { | ||
// val traced: StepAspect[Any, Nothing, Any, InstrumentationLogging with StepUidGenerator, Nothing, Nothing] = | ||
// new StepAspect[Any, Nothing, Any, InstrumentationLogging, Nothing, Nothing] { | ||
// def apply[ | ||
// SIn1 <: Any, | ||
// SOut1 >: Nothing, | ||
// Msg1 <: Any, | ||
// R1 <: InstrumentationLogging with StepUidGenerator, | ||
// E1 >: Nothing, | ||
// A1 >: Nothing | ||
// ]( | ||
// step: RunnableStep[SIn1, SOut1, Msg1, R1, E1, A1] | ||
// ): RunnableStep[SIn1, SOut1, Msg1, R1, E1, A1] = | ||
// Step(for { | ||
// | ||
// _ <- iLog.trace(InstrumentationEvent.stepExecutionStarted()) | ||
// res <- step.asEffect | ||
// } yield res) | ||
// } | ||
} |
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,8 @@ | ||
package morphir.flowz | ||
|
||
import zio.URIO | ||
|
||
object StepExecutionId { | ||
def nextExecutionId: URIO[StepUidGenerator, StepExecutionId] = | ||
uidGenerator.nextUid[Step.type] | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.