-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(runtime): move scheduler to library and make it possible to buil…
…d executable
- Loading branch information
1 parent
85b74f3
commit 973a8a7
Showing
8 changed files
with
81 additions
and
59 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 |
---|---|---|
@@ -1,6 +1,15 @@ | ||
module Main where | ||
|
||
import Control.Concurrent | ||
import StuntDouble | ||
import Scheduler | ||
|
||
------------------------------------------------------------------------ | ||
|
||
main :: IO () | ||
main = print =<< getNumCapabilities | ||
main = do | ||
let executorPort = 3004 | ||
executorRef = RemoteRef ("http://localhost:" ++ show executorPort) 0 | ||
el <- makeEventLoop realTime (makeSeed 0) HttpSync (EventLoopName "scheduler") | ||
lref <- spawn el (fakeScheduler executorRef) initState | ||
putStrLn "Scheduler is running..." | ||
waitForEventLoopQuit el |
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,53 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
module Scheduler where | ||
|
||
import Data.Text (Text) | ||
import qualified Data.Text as Text | ||
import Control.Exception | ||
import Control.Concurrent.Async | ||
|
||
import StuntDouble | ||
|
||
------------------------------------------------------------------------ | ||
|
||
initState :: State | ||
initState = stateFromList [ ("heap", heapFromList [(Integer 1, Text "cmd1")]) | ||
, ("time", epoch) | ||
, ("seed", Integer 0) | ||
] | ||
|
||
fakeScheduler :: RemoteRef -> Message -> Actor | ||
fakeScheduler executorRef (ClientRequest "CreateTest" cid) = Actor $ do | ||
-- load from db | ||
undefined | ||
fakeScheduler executorRef (ClientRequest "Start" cid) = Actor $ do | ||
-- pop agenda end send to executorRef | ||
r <- pop <$> gets "heap" | ||
case r of | ||
Some (Pair cmd heap') -> do | ||
update "heap" heap' | ||
p <- send executorRef (InternalMessage (prettyCommand cmd)) | ||
on p (\(InternalMessageR (InternalMessage "Ack")) -> undefined) | ||
undefined | ||
None -> return (InternalMessage "Done") -- XXX: reply to client id?! | ||
_otherwise -> error "scheduler: start: impossible" | ||
where | ||
prettyCommand :: Datatype -> String | ||
prettyCommand = undefined | ||
fakeScheduler executorRef msg@(InternalMessage "Ack") = Actor $ do | ||
undefined | ||
-- does executor send back anything else? | ||
-- schedule the responses from the executor back on the agenda | ||
|
||
-- XXX: we need to make messages be able to have args/fields/payload | ||
-- cmds <- parseCommands (payload msg) | ||
-- if no cmds and agenda is empty then stop (how do we contact client? need to save cid?) | ||
-- else | ||
-- now <- gets "time" | ||
-- seed <- gets "seed" | ||
-- arrivalTime <- genArrivalTime now seed | ||
-- op2 push arrivalTime (parseCommand resp) %= "heap" | ||
-- where | ||
-- parseCommand :: Message -> Datatype | ||
-- parseCommand (InternalMessage m) = Pair (Text (Text.pack (show m))) (List []) -- XXX: args |
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
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