aboutsummaryrefslogtreecommitdiff
path: root/server/src/Thermoprint/Server/API.hs
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2016-01-24 17:33:10 +0000
committerGregor Kleen <gkleen@yggdrasil.li>2016-01-24 17:33:10 +0000
commitb3a0d801d4f67aff2551cb5a7ece1a11db0887ec (patch)
tree63837bb9559533976258594069d88e132e10d677 /server/src/Thermoprint/Server/API.hs
parent4de9358c0a90f428163a95eecab3060170246236 (diff)
downloadthermoprint-b3a0d801d4f67aff2551cb5a7ece1a11db0887ec.tar
thermoprint-b3a0d801d4f67aff2551cb5a7ece1a11db0887ec.tar.gz
thermoprint-b3a0d801d4f67aff2551cb5a7ece1a11db0887ec.tar.bz2
thermoprint-b3a0d801d4f67aff2551cb5a7ece1a11db0887ec.tar.xz
thermoprint-b3a0d801d4f67aff2551cb5a7ece1a11db0887ec.zip
documentation
Diffstat (limited to 'server/src/Thermoprint/Server/API.hs')
-rw-r--r--server/src/Thermoprint/Server/API.hs3
1 files changed, 3 insertions, 0 deletions
diff --git a/server/src/Thermoprint/Server/API.hs b/server/src/Thermoprint/Server/API.hs
index bff8eed..2aa9cb8 100644
--- a/server/src/Thermoprint/Server/API.hs
+++ b/server/src/Thermoprint/Server/API.hs
@@ -88,6 +88,7 @@ thermoprintServer = listPrinters
88 infixr 9 <||> 88 infixr 9 <||>
89 89
90lookupPrinter :: Maybe PrinterId -> Handler (PrinterId, Printer) 90lookupPrinter :: Maybe PrinterId -> Handler (PrinterId, Printer)
91-- ^ Make sure a printer exists
91lookupPrinter pId = asks printers >>= maybePrinter' pId 92lookupPrinter pId = asks printers >>= maybePrinter' pId
92 where 93 where
93 maybePrinter' Nothing printerMap 94 maybePrinter' Nothing printerMap
@@ -98,9 +99,11 @@ lookupPrinter pId = asks printers >>= maybePrinter' pId
98 | otherwise = left $ err404 { errBody = "No such printer" } 99 | otherwise = left $ err404 { errBody = "No such printer" }
99 100
100queue' :: MonadIO m => Printer -> m Queue 101queue' :: MonadIO m => Printer -> m Queue
102-- ^ Call 'queue' and handle concurrency
101queue' = liftIO . readTVarIO . queue 103queue' = liftIO . readTVarIO . queue
102 104
103extractJobs :: (PrinterId, Queue) -> Seq (API.JobId, JobStatus) 105extractJobs :: (PrinterId, Queue) -> Seq (API.JobId, JobStatus)
106-- ^ Get an API-compatible list of all jobs from a 'Printer' 'Queue'
104extractJobs (pId, Queue pending current history) = fmap (, Queued pId) pending' <> maybe Seq.empty Seq.singleton (fmap (, Printing pId) current') <> fmap (second $ maybe Done Failed) history' 107extractJobs (pId, Queue pending current history) = fmap (, Queued pId) pending' <> maybe Seq.empty Seq.singleton (fmap (, Printing pId) current') <> fmap (second $ maybe Done Failed) history'
105 where 108 where
106 pending' = fmap (castId' . unJobKey) pending 109 pending' = fmap (castId' . unJobKey) pending