Skip to content

Commit

Permalink
Add url heartbeat type (mujx#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgy-komarov authored Apr 3, 2022
1 parent 2ea8a33 commit 96747c7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Dockerfile.arm
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ RUN yarn run prod && rm -rf .git
#
# Build the server.
#
FROM ubuntu:20.10 as server-builder
FROM ubuntu:21.04 as server-builder

WORKDIR /build

Expand All @@ -41,7 +41,7 @@ RUN cabal configure --disable-optimization && \
cabal build -j2 exe:hakatime && mkdir -p /app/bin && \
cp /build/dist-newstyle/build/*-linux/ghc-*/hakatime-*/x/hakatime/opt/build/hakatime/hakatime /app/bin/hakatime

FROM ubuntu:20.10
FROM ubuntu:21.04

ENV DEBIAN_FRONTEND=noninteractive

Expand Down
1 change: 1 addition & 0 deletions src/Haka/Db/Statements.hs
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ insertHeartBeat = Statement query params result True
entityText FileType = "file"
entityText AppType = "app"
entityText DomainType = "domain"
entityText UrlType = "url"

getProjectStats :: Statement (Text, Text, UTCTime, UTCTime, Int64) [ProjectStatRow]
getProjectStats = Statement query params result True
Expand Down
8 changes: 5 additions & 3 deletions src/Haka/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ data HeartbeatPayload = HeartbeatPayload
file_lines :: Maybe Int64,
-- | Name of the project.
project :: Maybe Text,
-- | Type of the entity that triggered the heartbeat (file, app, domain)
-- | Type of the entity that triggered the heartbeat (file, app, domain, url)
ty :: EntityType,
-- | Unix timestamp for when the heartbeat was generated.
time_sent :: Double
Expand All @@ -254,21 +254,23 @@ instance FromJSON HeartbeatPayload where
instance ToJSON HeartbeatPayload where
toJSON = genericToJSON convertReservedWords

data EntityType = FileType | AppType | DomainType
data EntityType = FileType | AppType | DomainType | UrlType
deriving (Eq, Show, Generic)

instance FromJSON EntityType where
parseJSON (A.String p) = case p of
"file" -> return FileType
"app" -> return AppType
"domain" -> return DomainType
_ -> fail "Value can only be one of ['file', 'app', 'domain']"
"url" -> return UrlType
_ -> fail "Value can only be one of ['file', 'app', 'domain', 'url']"
parseJSON _ = fail "Expected a string value"

instance ToJSON EntityType where
toJSON FileType = A.String "file"
toJSON AppType = A.String "app"
toJSON DomainType = A.String "domain"
toJSON UrlType = A.String "url"

data LeaderboardRow = LeaderboardRow
{ leadProject :: Text,
Expand Down

0 comments on commit 96747c7

Please sign in to comment.