Commit 7bc0337b authored by Bas Lijnse's avatar Bas Lijnse

Removed `runTasks` alternative main function.

It now possible to do the same with `doTasks`
parent d6aba26b
......@@ -2,16 +2,54 @@ definition module iTasks.Engine
/**
* This module provides the iTasks engine.
* This is the primary function that creates the complete
* environment in which worfklow specifications can be executed.
* environment in which tasks can be executed.
*/
from Data.Maybe import :: Maybe
from System.FilePath import :: FilePath
from Internet.HTTP import :: HTTPRequest
from System.Time import :: Timespec
from Internet.HTTP import :: HTTPRequest
import iTasks.WF.Definition
/*
* There are two ways tasks can be started:
* Interactively when a user requests it through the web,
* or directly when the application (server) is started,
*/
:: StartableTask
= WebTask !WebTask
| StartupTask !StartupTask
:: WebTask =
{ url :: !String
, task :: !WebTaskWrapper
}
:: StartupTask =
{ attributes :: !TaskAttributes
, task :: !TaskWrapper
}
:: WebTaskWrapper = E.a: WebTaskWrapper (HTTPRequest -> Task a) & iTask a
:: TaskWrapper = E.a: TaskWrapper (Task a) & iTask a
//Utility functions for creating collections of startable tasks
atRequest :: String (HTTPRequest -> Task a) -> StartableTask | iTask a
atStartup :: TaskAttributes (Task a) -> StartableTask | iTask a
publish :== atRequest //Backwards compatibility
class Startable a
where
toStartable :: !a -> [StartableTask]
instance Startable (Task a) | iTask a //Default as web task
instance Startable (HTTPRequest -> Task a) | iTask a //As web task
instance Startable StartableTask
instance Startable [StartableTask]
:: EngineOptions =
{ appName :: String
, appPath :: FilePath // Location of the application's executable
......@@ -69,57 +107,6 @@ startEngineWithOptions :== doTasksWithOptions
*/
defaultEngineCLIOptions :: [String] EngineOptions -> (!Maybe EngineOptions,![String])
/**
* Start a stripped task engine (without an HTTP server) with a list of tasks to be created
*/
runTasks :: a !*World -> *World | Runnable a
runTasksWithOptions :: ([String] EngineOptions -> (!Maybe EngineOptions,![String])) a !*World -> *World | Runnable a
/*
* There are two ways tasks can be started:
* Interactively when a user requests it through the web,
* or directly when the application (server) is started,
*/
:: StartableTask
= WebTask !WebTask
| StartupTask !StartupTask
:: WebTask =
{ url :: !String
, task :: !WebTaskWrapper
}
:: StartupTask =
{ attributes :: !TaskAttributes
, task :: !TaskWrapper
}
:: WebTaskWrapper = E.a: WebTaskWrapper (HTTPRequest -> Task a) & iTask a
:: TaskWrapper = E.a: TaskWrapper (Task a) & iTask a
//Utility functions for creating collections of startable tasks
atRequest :: String (HTTPRequest -> Task a) -> StartableTask | iTask a
atStartup :: TaskAttributes (Task a) -> StartableTask | iTask a
publish :== atRequest //Backwards compatibility
class Startable a
where
toStartable :: !a -> [StartableTask]
instance Startable (Task a) | iTask a //Default as web task
instance Startable (HTTPRequest -> Task a) | iTask a //As web task
instance Startable StartableTask
instance Startable [StartableTask]
// === Wrapping non-interactive tasks for running on the command line ===
class Runnable a
where
toRunnable :: !a -> [StartableTask]
instance Runnable (Task a) | iTask a
/**
* Determines the default options for an application
*/
......
......@@ -142,40 +142,8 @@ where
]
[BackgroundTask stopOnStable]
]
runTasksWithOptions :: ([String] EngineOptions -> (!Maybe EngineOptions,![String])) a !*World -> *World | Runnable a
runTasksWithOptions initFun runnable world
# (cli,world) = getCommandLine world
# (options,world) = defaultEngineOptions world
# (mbOptions,msg) = initFun cli options
# world = show msg world
| mbOptions =: Nothing = world
# (Just options) = mbOptions
# iworld = createIWorld options world
# (res,iworld) = initJSCompilerState iworld
| res =:(Error _) = show ["Fatal error: " +++ fromError res] (destroyIWorld iworld)
# iworld = serve startupTasks [] systemTasks (timeout options.timeout) iworld
= destroyIWorld iworld
where
startupTasks = [t \\ StartupTask t <- toRunnable runnable]
systemTasks =
[BackgroundTask updateClock
,BackgroundTask (processEvents MAX_EVENTS)
,BackgroundTask stopOnStable]
runTasks :: a !*World -> *World | Runnable a
runTasks tasks world = runTasksWithOptions (\c o -> (Just o,[])) tasks world
show :: ![String] !*World -> *World
show lines world
# (console,world) = stdio world
# console = seqSt (\s c -> fwrites (s +++ "\n") c) lines console
# (_,world) = fclose console world
= world
// The iTasks engine consist of a set of HTTP WebService
// The iTasks engine consist of a set of HTTP Web services
engineWebService :: [WebTask] -> [WebService (Map InstanceNo TaskOutput) (Map InstanceNo TaskOutput)]
engineWebService webtasks =
[taskUIService webtasks
......@@ -184,24 +152,19 @@ engineWebService webtasks =
,staticResourceService [url \\ {WebTask|url} <- webtasks]
]
show :: ![String] !*World -> *World
show lines world
# (console,world) = stdio world
# console = seqSt (\s c -> fwrites (s +++ "\n") c) lines console
# (_,world) = fclose console world
= world
atRequest :: String (HTTPRequest -> Task a) -> StartableTask | iTask a
atRequest url task = WebTask {WebTask|url = url, task = WebTaskWrapper task}
atStartup :: TaskAttributes (Task a) -> StartableTask | iTask a
atStartup attributes task = StartupTask {StartupTask|attributes = attributes, task = TaskWrapper task}
class Runnable a
where
toRunnable :: !a -> [StartableTask]
instance Runnable (Task a) | iTask a
where
toRunnable task = [StartupTask {StartupTask|attributes='DM'.newMap,task=TaskWrapper task}]
instance Runnable [StartableTask]
where
toRunnable list = list
class Startable a
where
toStartable :: !a -> [StartableTask]
......
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