diff options
| -rw-r--r-- | server/src/Thermoprint/Server/API.hs | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/server/src/Thermoprint/Server/API.hs b/server/src/Thermoprint/Server/API.hs index 5fbb18e..44b8402 100644 --- a/server/src/Thermoprint/Server/API.hs +++ b/server/src/Thermoprint/Server/API.hs | |||
| @@ -46,6 +46,7 @@ import Data.Traversable (mapM) | |||
| 46 | import Data.Bifunctor | 46 | import Data.Bifunctor |
| 47 | import Data.Monoid | 47 | import Data.Monoid |
| 48 | import Data.Maybe | 48 | import Data.Maybe |
| 49 | import Data.Function (on) | ||
| 49 | 50 | ||
| 50 | import Database.Persist | 51 | import Database.Persist |
| 51 | import Database.Persist.Sql | 52 | import Database.Persist.Sql |
| @@ -141,12 +142,14 @@ jobStatus jobId = maybe (left err404) return . lookup jobId . toList =<< listJob | |||
| 141 | abortJob :: API.JobId -> Handler () | 142 | abortJob :: API.JobId -> Handler () |
| 142 | abortJob jobId = do | 143 | abortJob jobId = do |
| 143 | printerIds <- asks (Map.keys . printers) | 144 | printerIds <- asks (Map.keys . printers) |
| 144 | forM_ printerIds $ \pId -> do | 145 | found <- fmap or . forM printerIds $ \pId -> do |
| 145 | (pId', p) <- lookupPrinter $ Just pId | 146 | (pId', p) <- lookupPrinter $ Just pId |
| 146 | found <- liftIO . atomically $ do | 147 | liftIO . atomically $ do |
| 147 | current <- readTVar $ queue p | 148 | current@(Queue pending _ _) <- readTVar $ queue p |
| 148 | modifyTVar' (queue p) $ force . (\q@(Queue pending _ _) -> q { pending = Seq.filter (/= castId jobId) pending }) | 149 | let filtered = Seq.filter (/= castId jobId) pending |
| 149 | undefined | 150 | writeTVar (queue p) $ current { pending = filtered } |
| 151 | return $ ((==) `on` length) pending filtered | ||
| 152 | when (not found) $ left err404 | ||
| 150 | 153 | ||
| 151 | listDrafts :: Handler (Map API.DraftId (Maybe DraftTitle)) | 154 | listDrafts :: Handler (Map API.DraftId (Maybe DraftTitle)) |
| 152 | listDrafts = return undefined | 155 | listDrafts = return undefined |
