send update notificaton when removing a queued transfer
This commit is contained in:
parent
0d80406b2b
commit
21bd92f077
2 changed files with 20 additions and 14 deletions
|
@ -136,9 +136,13 @@ getNextTransfer q dstatus acceptable = atomically $ do
|
||||||
|
|
||||||
{- Removes a transfer from the queue, if present, and returns True if it
|
{- Removes a transfer from the queue, if present, and returns True if it
|
||||||
- was present. -}
|
- was present. -}
|
||||||
dequeueTransfer :: TransferQueue -> Transfer -> IO Bool
|
dequeueTransfer :: TransferQueue -> DaemonStatusHandle -> Transfer -> IO Bool
|
||||||
dequeueTransfer q t = atomically $ do
|
dequeueTransfer q dstatus t = do
|
||||||
(l, removed) <- partition (\i -> fst i /= t) <$> readTVar (queuelist q)
|
ok <- atomically $ do
|
||||||
void $ writeTVar (queuesize q) (length l)
|
(l, removed) <- partition (\i -> fst i /= t) <$> readTVar (queuelist q)
|
||||||
void $ writeTVar (queuelist q) l
|
void $ writeTVar (queuesize q) (length l)
|
||||||
return $ not $ null removed
|
void $ writeTVar (queuelist q) l
|
||||||
|
return $ not $ null removed
|
||||||
|
when ok $
|
||||||
|
notifyTransfer dstatus
|
||||||
|
return ok
|
||||||
|
|
|
@ -160,14 +160,16 @@ startTransfer t = liftIO $ putStrLn "start"
|
||||||
cancelTransfer :: Transfer -> Handler ()
|
cancelTransfer :: Transfer -> Handler ()
|
||||||
cancelTransfer t = do
|
cancelTransfer t = do
|
||||||
webapp <- getYesod
|
webapp <- getYesod
|
||||||
{- remove queued transfer -}
|
let dstatus = daemonStatus webapp
|
||||||
void $ liftIO $ dequeueTransfer (transferQueue webapp) t
|
liftIO $ do
|
||||||
{- stop running transfer -}
|
{- remove queued transfer -}
|
||||||
maybe noop (void . liftIO . stop webapp) =<< running webapp
|
void $ dequeueTransfer (transferQueue webapp) dstatus t
|
||||||
|
{- stop running transfer -}
|
||||||
|
maybe noop (stop dstatus) =<< running dstatus
|
||||||
where
|
where
|
||||||
running webapp = liftIO $ M.lookup t . currentTransfers
|
running dstatus = M.lookup t . currentTransfers
|
||||||
<$> getDaemonStatus (daemonStatus webapp)
|
<$> getDaemonStatus dstatus
|
||||||
stop webapp info = do
|
stop dstatus info = void $ do
|
||||||
putStrLn $ "stopping transfer " ++ show info
|
putStrLn $ "stopping transfer " ++ show info
|
||||||
{- When there's a thread associated with the
|
{- When there's a thread associated with the
|
||||||
- transfer, it's killed first, to avoid it
|
- transfer, it's killed first, to avoid it
|
||||||
|
@ -175,7 +177,7 @@ cancelTransfer t = do
|
||||||
- failed when the transfer process is killed. -}
|
- failed when the transfer process is killed. -}
|
||||||
maybe noop killThread $ transferTid info
|
maybe noop killThread $ transferTid info
|
||||||
maybe noop killproc $ transferPid info
|
maybe noop killproc $ transferPid info
|
||||||
removeTransfer (daemonStatus webapp) t
|
removeTransfer dstatus t
|
||||||
{- In order to stop helper processes like rsync,
|
{- In order to stop helper processes like rsync,
|
||||||
- kill the whole process group of the process running the
|
- kill the whole process group of the process running the
|
||||||
- transfer. -}
|
- transfer. -}
|
||||||
|
|
Loading…
Reference in a new issue