| Safe Haskell | None |
|---|
System.Restricted.Worker
Description
Main entry point of the library
- module System.Restricted.Worker.Types
- module System.Restricted.Worker.Pool
- module System.Restricted.Worker.Protocol
- mkDefaultWorker :: String -> FilePath -> LimitSettings -> Worker a
- startWorker :: (WorkerData w, MonadIO (WMonad w), MonadBase (WMonad w) m) => String -> FilePath -> Maybe (IO Handle) -> LimitSettings -> WMonad w (WData w) -> (WData w -> Socket -> IO ()) -> WMonad w (Worker w, RestartWorker m w)
- startIOWorker :: String -> LimitSettings -> FilePath -> (Handle -> IO ()) -> IO (Worker IOWorker, RestartWorker IO IOWorker)
- killWorker :: Worker a -> IO (Worker a)
- workerAlive :: Worker a -> IO Bool
- connectToWorker :: Worker a -> IO Handle
Exposed modules
Creating workers
mkDefaultWorker :: String -> FilePath -> LimitSettings -> Worker aSource
Create an uninitialized worker
Arguments
| :: (WorkerData w, MonadIO (WMonad w), MonadBase (WMonad w) m) | |
| => String | Name |
| -> FilePath | Socket |
| -> Maybe (IO Handle) | Where to redirect stdout, stderr |
| -> LimitSettings | Restrictions |
| -> WMonad w (WData w) | Pre-forking action |
| -> (WData w -> Socket -> IO ()) | Socket callback |
| -> WMonad w (Worker w, RestartWorker m w) |
Start a general type of worker.
The pre-forking action is a monadic action that will be run prior to
calling forkWorker. It might be some initialization code, running the
DB query, anything you want. The resulting WData will be passed to
the callback.
The socket that is passed to the callback is a server socket.
Arguments
| :: String | Name |
| -> LimitSettings | Restrictions |
| -> FilePath | UNIX socket |
| -> (Handle -> IO ()) | Callback |
| -> IO (Worker IOWorker, RestartWorker IO IOWorker) |
Start a worker of type IOWorker
The callback function is called every time a connectino is established
>>>startIOWorker "test" "/tmp/test.sock" $ \h -> hPutStrLn h "hello, world"
Quering and killing workers
killWorker :: Worker a -> IO (Worker a)Source
Kill a worker. Takes an initialized worker, returns non-initialized one.
workerAlive :: Worker a -> IO BoolSource
Checks whether the worker is alive
connectToWorker :: Worker a -> IO HandleSource
Connect to the worker's socket and return a handle