Skip to content

Instantly share code, notes, and snippets.

@zainab-ali
Created February 26, 2017 18:45
Show Gist options
  • Save zainab-ali/f74c9f2540121c50ea2ceedc88d915a7 to your computer and use it in GitHub Desktop.
Save zainab-ali/f74c9f2540121c50ea2ceedc88d915a7 to your computer and use it in GitHub Desktop.
drone dynamic
package drone
import fs2._
import java.time.Instant
import java.util.UUID
object Time {
def local: Task[Instant] = Task.delay(Instant.now())
}
object Agent {
sealed trait Work
}
trait Agent {
def queue(work: Agent.Work): Task[UUID] = ???
def completed: Stream[Task, Agent.Work] = ???
def stop: Task[Unit] = ???
}
object Node {
type State = List[Agent]
}
sealed trait Node {
def stop: Task[Unit] = ???
}
sealed trait Container {
def node: Task[Node] = ???
def agent(node: Node): Task[Agent] = ???
}
sealed trait Job
object Dispatcher {
case class State(node: Map[Node, Node.State])
}
final class Dispatcher(
time: Task[Instant],
container: Container,
jobs: Stream[Task, Job]
) {
def run(state: Dispatcher.State): Task[Unit] = {
jobs.scan(Task.now(state)) { (current, job) =>
//Logic using container, etc.. goes here returning a task
current
}.flatMap(Stream.eval).run
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment