implementation module iTasks._Framework.Engine import StdMisc, StdArray, StdList, StdOrdList, StdTuple, StdChar, StdFile, StdBool, StdEnum from StdFunc import o, seqList, ::St, const from Data.Map import :: Map import qualified Data.Map as DM import Data.Error, Data.Func, Data.Tuple, Math.Random, Internet.HTTP, Text, Text.Encodings.MIME, Text.Encodings.UrlEncoding import System.Time, System.CommandLine, System.Environment, System.OSError, System.File, System.FilePath, System.Directory import iTasks._Framework.Util, iTasks._Framework.HtmlUtil import iTasks._Framework.IWorld, iTasks._Framework.WebService, iTasks._Framework.SDSService import iTasks.API.Common.SDSCombinators CLEAN_HOME_VAR :== "CLEAN_HOME" SESSION_TIMEOUT :== fromString "0000-00-00 00:10:00" //The following modules are excluded by the SAPL -> Javascript compiler //because they contain functions implemented in ABC code that cannot //be compiled to javascript anyway. Handwritten Javascript overrides need //to be provided for them. JS_COMPILER_EXCLUDES :== ["iTasks._Framework.Client.Override" ,"dynamic_string" ,"graph_to_string_with_descriptors" ,"graph_to_sapl_string" ,"Text.Encodings.Base64" ,"Sapl.LazyLinker" ,"Sapl.Target.JS.CodeGeneratorJS" ,"System.Pointer" ,"System.File" ,"System.Directory" ] import StdInt, StdChar, StdString import tcp import Internet.HTTP, System.Time, System.CommandLine, Data.Func import iTasks._Framework.Engine, iTasks._Framework.IWorld, iTasks._Framework.TaskEval, iTasks._Framework.TaskStore import iTasks._Framework.Util import iTasks._Framework.TaskServer from Data.Set import :: Set, newSet from Sapl.Linker.LazyLinker import generateLoaderState, :: LoaderStateExt from Sapl.Linker.SaplLinkerShared import :: SkipSet from Sapl.Target.Flavour import :: Flavour, toFlavour startEngine :: a !*World -> *World | Publishable a startEngine publishable world # (opts,world) = getCommandLine world # (app,world) = determineAppName world # (mbSDKPath,world) = determineSDKPath SEARCH_PATHS world // Show server name # world = show (infoline app) world //Check options # port = fromMaybe DEFAULT_PORT (intOpt "-port" opts) # keepalive = fromMaybe DEFAULT_KEEPALIVE_TIME (intOpt "-keepalive" opts) # help = boolOpt "-help" opts # sdkOpt = stringOpt "-sdk" opts # webDirsOpt = stringOpt "-webpublic" opts # webDirPaths = fmap (split ":") webDirsOpt # storeOpt = stringOpt "-store" opts # saplOpt = stringOpt "-sapl" opts //If -help option is given show help and stop | help = show instructions world //Check sdkpath # mbSDKPath = maybe mbSDKPath Just sdkOpt //Commandline SDK option overrides found paths //Normal execution # world = show (running port) world # iworld = initIWorld mbSDKPath webDirPaths storeOpt saplOpt world //Reset connectedTo for all task instances # iworld = clearConnections iworld // mark all instance as outdated initially # iworld = queueAllPersistent iworld //Start task server # iworld = serve port (httpServer port keepalive (engine publishable) taskOutput) [BackgroundTask removeOutdatedSessions,BackgroundTask refreshTaskInstances] timeout iworld = finalizeIWorld iworld where infoline :: !String -> [String] infoline app = ["*** " +++ app +++ " HTTP server ***",""] instructions :: [String] instructions = ["Available commandline options:" ," -help : Show this message and exit" ," -sdk : Use as location of the iTasks SDK (optional)" ," -webpublic : Use to point to the folders that contain the application's static web content" ," -store : Use as data store location" ," -sapl : Use to point to the folders that hold the sapl version of the application" ," -port : Set port number (default " +++ toString DEFAULT_PORT +++ ")" ," -keepalive