From 90b24d989b0d5d10bc79fcf76377b1197cfe8eb9 Mon Sep 17 00:00:00 2001 From: Lucy Cifferello Date: Mon, 6 Jul 2020 16:41:45 -0600 Subject: [PATCH] clean up logic for recording metrics --- src/Handler/Apps.hs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/Handler/Apps.hs b/src/Handler/Apps.hs index 20a7ff0..e799c8b 100644 --- a/src/Handler/Apps.hs +++ b/src/Handler/Apps.hs @@ -71,15 +71,22 @@ getApp rootDir ext@(Extension appId) = do case getSpecifiedAppVersion spec appVersions of Nothing -> notFound Just (RegisteredAppVersion (appVersion, filePath)) -> do - exists <- liftIO $ doesFileExist filePath let isApp = isInfixOf "apps" rootDir - if isApp then toTypedContent <$> recordMetrics appId rootDir appVersion - else if exists - then do - sz <- liftIO $ fileSize <$> getFileStatus filePath - addHeader "Content-Length" (show sz) - respondSource typePlain $ CB.sourceFile filePath .| awaitForever sendChunkBS - else notFound + exists <- liftIO $ doesFileExist filePath + determineEvent exists isApp filePath appVersion + where + determineEvent True False fp _ = do + sz <- liftIO $ fileSize <$> getFileStatus fp + addHeader "Content-Length" (show sz) + respondSource typePlain $ CB.sourceFile fp .| awaitForever sendChunkBS + determineEvent True True fp av = do + _ <- recordMetrics appId rootDir av + sz <- liftIO $ fileSize <$> getFileStatus fp + addHeader "Content-Length" (show sz) + respondSource typePlain $ CB.sourceFile fp .| awaitForever sendChunkBS + determineEvent False _ _ _ = notFound + + errOnNothing :: MonadHandler m => Status -> Text -> Maybe a -> m a errOnNothing status res entity = case entity of