diff options
author | Joey Hess <joey@kitenet.net> | 2012-08-08 17:55:56 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2012-08-08 17:55:56 -0400 |
commit | 20203b45b9dbf915851969b9c5f4c9cb6e71acb6 (patch) | |
tree | 62b352950dd0f044f1b5aaee9baa4af2e02d80fd /Assistant/WebApp/DashBoard.hs | |
parent | 09449792fa50686e2fb9af6c392b8644dddae5d6 (diff) |
transfer canceling
Should work (untested) for transfers being run by other processes.
Not yet by transfers being run by the assistant. killThread does not
kill processes forked off by a thread. To fix this, will probably
need to make `git annex getkey` and `git annex sendkey` commands that
operate on keys, and write their own transfer info. Then the assistant
can run them, and kill them, as needed.
Diffstat (limited to 'Assistant/WebApp/DashBoard.hs')
-rw-r--r-- | Assistant/WebApp/DashBoard.hs | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/Assistant/WebApp/DashBoard.hs b/Assistant/WebApp/DashBoard.hs index 57d789831..08aeb78c5 100644 --- a/Assistant/WebApp/DashBoard.hs +++ b/Assistant/WebApp/DashBoard.hs @@ -29,6 +29,7 @@ import Yesod import Text.Hamlet import qualified Data.Map as M import Control.Concurrent +import System.Posix.Signals (signalProcess, sigTERM, sigKILL) {- A display of currently running and queued transfers. - @@ -161,4 +162,21 @@ startTransfer :: Transfer -> Handler () startTransfer t = liftIO $ putStrLn "start" cancelTransfer :: Transfer -> Handler () -cancelTransfer t = liftIO $ putStrLn "cancel" +cancelTransfer t = do + webapp <- getYesod + {- Remove if queued. -} + void $ liftIO $ dequeueTransfer (transferQueue webapp) t + {- When the transfer is running, don't directly remove it from the + - map, instead signal to end the transfer, and rely on the + - TransferWatcher to notice it's done and update the map. -} + mi <- liftIO $ M.lookup t . currentTransfers + <$> getDaemonStatus (daemonStatus webapp) + case mi of + Just (TransferInfo { transferTid = Just tid } ) -> do + -- TODO + error "TODO" + Just (TransferInfo { transferPid = Just pid } ) -> liftIO $ do + signalProcess sigTERM pid + threadDelay 500000 -- half a second grace period + signalProcess sigKILL pid + _ -> noop |