mirror of
https://github.com/github/semantic.git
synced 2024-11-29 02:44:36 +03:00
Add withGitmonStatus
This commit is contained in:
parent
5df5581507
commit
c4dd79717f
@ -72,15 +72,12 @@ reportGitmon' SocketFactory{..} program gitCommand = do
|
|||||||
(gitDir, realIP, repoName) <- liftIO loadEnvVars
|
(gitDir, realIP, repoName) <- liftIO loadEnvVars
|
||||||
(startTime, beforeProcIOContents) <- liftIO collectStats
|
(startTime, beforeProcIOContents) <- liftIO collectStats
|
||||||
|
|
||||||
maybeCommand <- safeIO . timeout gitmonTimeout . withSocket $ \s -> do
|
gitmonStatus <- safeIO . timeout gitmonTimeout . withSocket $ \s -> do
|
||||||
sendAll s $ processJSON Update (ProcessUpdateData gitDir program realIP repoName "semantic-diff")
|
sendAll s $ processJSON Update (ProcessUpdateData gitDir program realIP repoName "semantic-diff")
|
||||||
sendAll s $ processJSON Schedule ProcessScheduleData
|
sendAll s $ processJSON Schedule ProcessScheduleData
|
||||||
recv s 1024
|
recv s 1024
|
||||||
|
|
||||||
!result <- case join maybeCommand of
|
!result <- withGitmonStatus (join gitmonStatus) gitCommand
|
||||||
Just command | "fail" `isInfixOf` decodeUtf8 command ->
|
|
||||||
throw . GitmonException . unpack $ "Received '" <> decodeUtf8 command <> "' from Gitmon"
|
|
||||||
_ -> gitCommand
|
|
||||||
|
|
||||||
(afterTime, afterProcIOContents) <- liftIO collectStats
|
(afterTime, afterProcIOContents) <- liftIO collectStats
|
||||||
let (cpuTime, diskReadBytes, diskWriteBytes, resultCode) = procStats startTime afterTime beforeProcIOContents afterProcIOContents
|
let (cpuTime, diskReadBytes, diskWriteBytes, resultCode) = procStats startTime afterTime beforeProcIOContents afterProcIOContents
|
||||||
@ -89,6 +86,14 @@ reportGitmon' SocketFactory{..} program gitCommand = do
|
|||||||
pure result
|
pure result
|
||||||
|
|
||||||
where
|
where
|
||||||
|
withGitmonStatus :: Maybe ByteString -> ReaderT LgRepo IO a -> ReaderT LgRepo IO a
|
||||||
|
withGitmonStatus maybeGitmonStatus gitCommand = case maybeGitmonStatus of
|
||||||
|
Just gitmonStatus | "fail" `isInfixOf` decodeUtf8 gitmonStatus -> throwGitmonException gitmonStatus
|
||||||
|
_ -> gitCommand
|
||||||
|
|
||||||
|
throwGitmonException :: ByteString -> e
|
||||||
|
throwGitmonException command = throw . GitmonException . unpack $ "Received from Gitmon: '" <> decodeUtf8 command <> "' from Gitmon"
|
||||||
|
|
||||||
collectStats :: IO (TimeSpec, ProcInfo)
|
collectStats :: IO (TimeSpec, ProcInfo)
|
||||||
collectStats = do
|
collectStats = do
|
||||||
time <- getTime clock
|
time <- getTime clock
|
||||||
|
Loading…
Reference in New Issue
Block a user