Commit fec3df28 authored by Mart Lubbers's avatar Mart Lubbers

Remove processEvents backgroundtask

This cannot be a regular task since it always needs to run at the end
parent 7d4804dd
Pipeline #19951 passed with stage
in 4 minutes and 41 seconds
......@@ -58,21 +58,22 @@ instance Startable (a,b) | Startable a & Startable b
:: EngineOptions =
{ appName :: String
, appPath :: FilePath // Location of the application's executable
{ appName :: String
, appPath :: FilePath // Location of the application's executable
, appVersion :: String
, serverPort :: Int
, serverUrl :: String
, serverPort :: Int
, serverUrl :: String
, keepaliveTime :: Timespec
, sessionTime :: Timespec
, persistTasks :: Bool
, sessionTime :: Timespec
, persistTasks :: Bool
, autoLayout :: Bool
, maxEvents :: Int
, timeout :: Maybe Int // The timeout
, distributed :: Bool
, sdsPort :: Int
, webDirPath :: FilePath // Location of public files that are served by the iTask webserver
, storeDirPath :: FilePath // Location of the application's persistent data files
, tempDirPath :: FilePath // Location for temporary files used in tasks
, sdsPort :: Int
, webDirPath :: FilePath // Location of public files that are served by the iTask webserver
, storeDirPath :: FilePath // Location of the application's persistent data files
, tempDirPath :: FilePath // Location for temporary files used in tasks
, saplDirPath :: FilePath // Location of the application's sapl files (client-side code)
}
......
......@@ -60,26 +60,21 @@ doTasksWithOptions initFun startable world
# (symbolsResult, iworld) = initSymbolsShare options.distributed options.appName iworld
| symbolsResult =: (Error _) = show ["Error reading symbols while required: " +++ fromError symbolsResult] (destroyIWorld iworld)
# iworld = serve (startupTasks options) (tcpTasks options.serverPort options.keepaliveTime)
engineTasks (timeout options.timeout) iworld
[] (timeout options.timeout) iworld
= destroyIWorld iworld
where
webTasks = [t \\ WebTask t <- toStartable startable]
startupTasks {distributed, sdsPort}
//If distributed, start sds service task
= (if distributed [startTask (sdsServiceTask sdsPort)] [])
++ [startTask flushWritesWhenIdle]
++ (if hasWebTasks
//If there are webtasks, we need to clean up sessions
[startTask removeOutdatedSessions]
//If there are none, we need to stop when all tasks are stable
[startTask stopOnStable]
++ [startTask flushWritesWhenIdle
//If there no webtasks, stop when stable, otherwise cleanup old sessions
,startTask if (webTasks =: []) stopOnStable removeOutdatedSessions
//Start all startup tasks
)++ [t \\ StartupTask t <- toStartable startable]
:[t \\ StartupTask t <- toStartable startable]]
startTask t = {StartupTask|attributes=defaultValue,task=TaskWrapper t}
hasWebTasks = not (webTasks =: [])
initSymbolsShare False _ iworld = (Ok (), iworld)
initSymbolsShare True appName iworld = case storeSymbols (IF_WINDOWS (appName +++ ".exe") appName) iworld of
(Error (e, s), iworld) = (Error s, iworld)
......@@ -91,8 +86,6 @@ where
| otherwise
= [(serverPort,httpServer serverPort keepaliveTime (engineWebService webTasks) taskOutput)]
engineTasks = [BackgroundTask (processEvents MAX_EVENTS)]
// The iTasks engine consist of a set of HTTP Web services
engineWebService :: [WebTask] -> [WebService (Map InstanceNo TaskOutput) (Map InstanceNo TaskOutput)]
engineWebService webtasks =
......@@ -127,6 +120,8 @@ where
"Specify the timeout in ms (default: 500)\nIf not given, use an indefinite timeout."
, Option [] ["keepalive"] (ReqArg (\p->fmap \o->{o & keepaliveTime={tv_sec=toInt p,tv_nsec=0}}) "SECONDS")
"Specify the keepalive time in seconds (default: 300)"
, Option [] ["maxevents"] (ReqArg (\p->fmap \o->{o & maxEvents=toInt p}) "NUM")
"Specify the maximum number of events to process per loop (default: 5)"
, Option [] ["sessiontime"] (ReqArg (\p->fmap \o->{o & sessionTime={tv_sec=toInt p,tv_nsec=0}}) "SECONDS")
"Specify the expiry time for a session in seconds (default: 60)"
, Option [] ["autolayout"] (NoArg (fmap \o->{o & autoLayout=True}))
......@@ -213,22 +208,23 @@ defaultEngineOptions world
# appDir = takeDirectory appPath
# appName = (dropExtension o dropDirectory) appPath
# options =
{ appName = appName
, appPath = appPath
, appVersion = appVersion
, serverPort = IF_POSIX_OR_WINDOWS 8080 80
, serverUrl = "http://localhost/"
, keepaliveTime = {tv_sec=300,tv_nsec=0} // 5 minutes
, sessionTime = {tv_sec=60,tv_nsec=0} // 1 minute, (the client pings every 10 seconds by default)
, persistTasks = False
, autoLayout = True
, distributed = False
, sdsPort = 9090
, timeout = Just 500
, webDirPath = appDir </> appName +++ "-www"
, storeDirPath = appDir </> appName +++ "-data" </> "stores"
, tempDirPath = appDir </> appName +++ "-data" </> "tmp"
, saplDirPath = appDir </> appName +++ "-sapl"
{ appName = appName
, appPath = appPath
, appVersion = appVersion
, serverPort = IF_POSIX_OR_WINDOWS 8080 80
, serverUrl = "http://localhost/"
, keepaliveTime = {tv_sec=300,tv_nsec=0} // 5 minutes
, sessionTime = {tv_sec=60,tv_nsec=0} // 1 minute, (the client pings every 10 seconds by default)
, persistTasks = False
, autoLayout = True
, distributed = False
, maxEvents = 5
, sdsPort = 9090
, timeout = Just 500
, webDirPath = appDir </> appName +++ "-www"
, storeDirPath = appDir </> appName +++ "-data" </> "stores"
, tempDirPath = appDir </> appName +++ "-data" </> "tmp"
, saplDirPath = appDir </> appName +++ "-sapl"
}
= (options,world)
......
......@@ -132,6 +132,7 @@ createClientIWorld serverURL currentInstance
, autoLayout = True
, timeout = Just 100
, distributed = False
, maxEvents = 5
, sdsPort = 9090
, webDirPath = locundef "webDirectory"
, storeDirPath = locundef "dataDirectory"
......
......@@ -29,10 +29,11 @@ addConnection :: !TaskId !String !Int !ConnectionTask !*IWorld -> (!MaybeError T
//Dynamically add a background task
addBackgroundTask :: !BackgroundTask !*IWorld -> (!MaybeError TaskException BackgroundTaskId,!*IWorld)
ioStateString :: !IOStates -> String
//Dynamically remove a background task
removeBackgroundTask :: !BackgroundTaskId !*IWorld -> (!MaybeError TaskException (),!*IWorld)
//ioStateString :: !IOStates -> String
//Ticks every time the server loops once
tick :: SDSSource () () ()
......@@ -80,12 +80,15 @@ loop determineTimeout iworld=:{ioTasks,sdsNotifyRequests}
//Check which mainloop tasks have data available
# (todo,chList,world) = select mbTimeout todo world
# (merr, iworld) = updateClock {iworld & ioTasks = {done=[],todo=todo}, world = world}
| merr=:(Error _) = abort "Error updating clock"
| merr=:(Error _) = abort "Error updating clock\n"
// Write ticker
# (merr, iworld) = write () tick EmptyContext iworld
| isError merr = abort "Error writing ticker"
| isError merr = abort "Error writing ticker\n"
//Process the select result
# iworld =:{shutdown,ioTasks={done}} = process 0 chList iworld
# iworld=:{options} = process 0 chList iworld
//Process the events it created
# (merr, iworld=:{shutdown,ioTasks={done}}) = processEvents options.maxEvents {iworld & options=options}
| isError merr = abort "Error processing events\n"
//Move everything from the done list back to the todo list
# iworld = {iworld & ioTasks={todo = reverse done,done=[]}}
//Everything needs to be re-evaluated
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment