conflict resolution (#77)

This commit is contained in:
Keagan McClelland
2021-11-23 15:55:45 -07:00
parent e6009e9658
commit ca5cbefd68
2 changed files with 44 additions and 14 deletions

View File

@@ -8,20 +8,25 @@ import Data.Aeson ( (.:)
, withObject , withObject
, withText , withText
) )
import qualified Data.Text as T
import Foundation import Foundation
import Settings ( AppSettings(errorLogRoot) ) import Model ( EntityField(ErrorLogRecordIncidents)
import Startlude hiding ( Handler ) , ErrorLogRecord(ErrorLogRecord)
import System.FilePath ( (<.>)
, (</>)
) )
import Yesod.Core ( getsYesod import Startlude hiding ( Handler )
, requireCheckJsonBody import Yesod.Core ( requireCheckJsonBody )
import Yesod.Persist ( (+=.)
, runDB
, upsert
) )
data ErrorLog = ErrorLog data ErrorLog = ErrorLog
{ errorLogEpoch :: Word64 { errorLogEpoch :: Word64
, errorLogMessage :: Text , errorLogCommitHash :: Text
, errorLogSourceFile :: Text
, errorLogLine :: Word32
, errorLogTarget :: Text
, errorLogLevel :: Text
, errorLogMessage :: Text
} }
deriving (Eq, Show) deriving (Eq, Show)
@@ -33,14 +38,27 @@ instance FromJSON ErrorLog where
Nothing -> fail "Invalid Log Epoch" Nothing -> fail "Invalid Log Epoch"
Just x -> pure x Just x -> pure x
) )
errorLogMessage <- o .: "log-message" errorLogCommitHash <- o .: "commit-hash"
errorLogSourceFile <- o .: "file"
errorLogLine <- o .: "line"
errorLogLevel <- o .: "level"
errorLogTarget <- o .: "target"
errorLogMessage <- o .: "log-message"
pure ErrorLog { .. } pure ErrorLog { .. }
postErrorLogsR :: Handler () postErrorLogsR :: Handler ()
postErrorLogsR = do postErrorLogsR = do
ErrorLog {..} <- requireCheckJsonBody @_ @ErrorLog ErrorLog {..} <- requireCheckJsonBody @_ @ErrorLog
root <- getsYesod $ errorLogRoot . appSettings void $ runDB $ do
void $ liftIO $ forkIO $ appendFile (root </> show errorLogEpoch <.> "log") $ if "\n" `T.isSuffixOf` errorLogMessage now <- liftIO getCurrentTime
then errorLogMessage let logRecord = ErrorLogRecord now
else T.snoc errorLogMessage '\n' errorLogEpoch
errorLogCommitHash
errorLogSourceFile
errorLogLine
errorLogTarget
errorLogLevel
errorLogMessage
1
upsert logRecord [ErrorLogRecordIncidents +=. 1]

View File

@@ -79,4 +79,16 @@ EosHash
version Version version Version
hash Text hash Text
UniqueVersion version UniqueVersion version
ErrorLogRecord
createdAt UTCTime
epoch Word64
commitHash Text
sourceFile Text
line Word32
target Text
level Text
message Text
incidents Word32
UniqueLogRecord epoch commitHash sourceFile line target level message
|] |]