2021-10-06 09:30:38 +00:00
|
|
|
|
|
|
|
import
|
|
|
|
std/typetraits, preserves
|
|
|
|
|
|
|
|
type
|
2021-11-03 18:21:52 +00:00
|
|
|
`State`* {.preservesOr.} = enum
|
|
|
|
`started`, `ready`, `failed`, `complete`
|
|
|
|
ServiceObject*[E] {.preservesRecord: "service-object".} = ref object
|
2021-10-06 09:30:38 +00:00
|
|
|
`serviceName`*: Preserve[E]
|
2021-11-03 18:21:52 +00:00
|
|
|
`object`*: Preserve[E]
|
2021-10-06 09:30:38 +00:00
|
|
|
|
2021-11-03 18:21:52 +00:00
|
|
|
CoreService*[E] {.preservesRecord: "core-service".} = ref object
|
2021-10-06 09:30:38 +00:00
|
|
|
`serviceName`*: Preserve[E]
|
|
|
|
|
2021-09-24 19:25:47 +00:00
|
|
|
RequireService*[E] {.preservesRecord: "require-service".} = ref object
|
2021-10-06 09:30:38 +00:00
|
|
|
`serviceName`*: Preserve[E]
|
|
|
|
|
2021-09-24 19:25:47 +00:00
|
|
|
RunService*[E] {.preservesRecord: "run-service".} = ref object
|
2021-10-06 09:30:38 +00:00
|
|
|
`serviceName`*: Preserve[E]
|
|
|
|
|
2021-11-03 18:21:52 +00:00
|
|
|
ServiceState*[E] {.preservesRecord: "service-state".} = ref object
|
2021-09-24 19:25:47 +00:00
|
|
|
`serviceName`*: Preserve[E]
|
2021-11-03 18:21:52 +00:00
|
|
|
`state`*: State
|
2021-10-06 09:30:38 +00:00
|
|
|
|
2021-09-24 19:25:47 +00:00
|
|
|
ServiceDependency*[E] {.preservesRecord: "depends-on".} = ref object
|
|
|
|
`depender`*: Preserve[E]
|
2021-11-03 18:21:52 +00:00
|
|
|
`dependee`*: ServiceState[E]
|
2021-10-06 09:30:38 +00:00
|
|
|
|
2021-11-03 18:21:52 +00:00
|
|
|
proc `$`*[E](x: ServiceObject[E] | CoreService[E] | RequireService[E] |
|
2021-09-24 19:25:47 +00:00
|
|
|
RunService[E] |
|
2021-11-03 18:21:52 +00:00
|
|
|
ServiceState[E] |
|
2021-09-24 19:25:47 +00:00
|
|
|
ServiceDependency[E]): string =
|
2021-10-06 09:30:38 +00:00
|
|
|
`$`(toPreserve(x, E))
|
|
|
|
|
2021-11-03 18:21:52 +00:00
|
|
|
proc encode*[E](x: ServiceObject[E] | CoreService[E] | RequireService[E] |
|
2021-09-24 19:25:47 +00:00
|
|
|
RunService[E] |
|
2021-11-03 18:21:52 +00:00
|
|
|
ServiceState[E] |
|
2021-09-24 19:25:47 +00:00
|
|
|
ServiceDependency[E]): seq[byte] =
|
2021-10-06 09:30:38 +00:00
|
|
|
encode(toPreserve(x, E))
|