Skip to content

Commit

Permalink
Merge pull request #38 from ambarltd/utils
Browse files Browse the repository at this point in the history
Use ambar-hs-utils
  • Loading branch information
lazamar authored Jan 8, 2025
2 parents 0250711 + 0cfd293 commit 421e394
Show file tree
Hide file tree
Showing 43 changed files with 93 additions and 1,023 deletions.
4 changes: 2 additions & 2 deletions benchmarks/Benchmarks.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import Ambar.Emulator.Queue.Partition (Record(..), Position(..))
import qualified Ambar.Emulator.Queue.Partition as P
import Ambar.Emulator.Queue.Partition.File (FilePartition)
import qualified Ambar.Emulator.Queue.Partition.File as F
import Utils.Some (Some(..))
import Utils.Warden as Warden
import Util.Some (Some(..))
import Util.Warden as Warden

main :: IO ()
main =
Expand Down
5 changes: 5 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
with-compiler: ghc-9.10.1
packages: .

source-repository-package
type: git
location: https://github.com/ambarltd/ambar-hs-utils
tag: 55334ab4af375ac19f4bbbd1a20071998f9b2306
19 changes: 5 additions & 14 deletions emulator.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ executable emulator
other-modules:
build-depends:
base
, ambar-hs-utils
, directory
, emulator-lib
, filepath
Expand Down Expand Up @@ -60,17 +61,9 @@ library emulator-lib
Ambar.Transport.File
Database.MySQL
Database.MicrosoftSQLServer
Utils.Async
Utils.Delay
Utils.Directory
Utils.Exception
Utils.Logger
Utils.Prettyprinter
Utils.STM
Utils.Some
Utils.Warden
build-depends:
base
, ambar-hs-utils
, aeson
, aeson-pretty
, async
Expand Down Expand Up @@ -124,15 +117,12 @@ test-suite emulator-tests
Test.Connector.PostgreSQL
Test.Connector.MicrosoftSQLServer
Test.Emulator
Test.OnDemand
Test.Transport
Test.Warden
Test.Utils.OnDemand
Test.Utils.Docker
Test.Utils.SQL
Test.Util.SQL
type: exitcode-stdio-1.0
build-depends:
base
, ambar-hs-utils
, emulator-lib
, aeson
, async
Expand Down Expand Up @@ -166,6 +156,7 @@ benchmark emulator-bench
main-is: benchmarks/Benchmarks.hs
build-depends:
base
, ambar-hs-utils
, emulator-lib
, async
, bytestring
Expand Down
10 changes: 5 additions & 5 deletions src/Ambar/Emulator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ import Ambar.Emulator.Config
, DataDestination(..)
, Destination(..)
)
import Utils.Delay (every, seconds)
import Utils.Directory (writeAtomically)
import Utils.Logger (SimpleLogger, annotate, logInfo, logDebugAction)
import Utils.Some (Some(..))
import Utils.STM (atomicallyNamed)
import Util.Delay (every, seconds)
import Util.Directory (writeAtomically)
import Util.Logger (SimpleLogger, annotate, logInfo, logDebugAction)
import Util.Some (Some(..))
import Util.STM (atomicallyNamed)

emulate :: SimpleLogger -> EmulatorConfig -> EnvironmentConfig -> IO ()
emulate logger_ config env = do
Expand Down
2 changes: 1 addition & 1 deletion src/Ambar/Emulator/Connector.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Control.Concurrent.STM (STM)
import Control.Exception (Exception)

import Ambar.Emulator.Queue.Topic (Producer, Partitioner, Encoder)
import Utils.Logger (SimpleLogger)
import Util.Logger (SimpleLogger)

class Connector a where
type ConnectorState a = b | b -> a
Expand Down
8 changes: 4 additions & 4 deletions src/Ambar/Emulator/Connector/File.hs
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ import Ambar.Emulator.Queue.Partition.File
import Ambar.Emulator.Queue.Topic (modPartitioner)
import Ambar.Emulator.Queue.Topic (Producer)
import qualified Ambar.Emulator.Queue.Topic as Topic
import Utils.Async (withAsyncThrow)
import Utils.Logger (SimpleLogger, fatal, logInfo)
import Utils.Delay (Duration, delay, millis)
import Utils.Prettyprinter (prettyJSON, renderPretty, commaSeparated)
import Util.Async (withAsyncThrow)
import Util.Logger (SimpleLogger, fatal, logInfo)
import Util.Delay (Duration, delay, millis)
import Util.Prettyprinter (prettyJSON, renderPretty, commaSeparated)

_POLLING_INTERVAL :: Duration
_POLLING_INTERVAL = millis 50
Expand Down
8 changes: 4 additions & 4 deletions src/Ambar/Emulator/Connector/MicrosoftSQLServer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ import Ambar.Emulator.Queue.Topic (Producer, hashPartitioner)
import Ambar.Record (Record(..), Value(..), Type(..), Bytes(..), TimeStamp(..))
import qualified Ambar.Record.Encoding as Encoding

import Utils.Delay (Duration, millis, seconds)
import Utils.Async (withAsyncThrow)
import Utils.Logger (SimpleLogger, logDebug, logInfo)
import Utils.Prettyprinter (renderPretty, sepBy, commaSeparated, prettyJSON)
import Util.Delay (Duration, millis, seconds)
import Util.Async (withAsyncThrow)
import Util.Logger (SimpleLogger, logDebug, logInfo)
import Util.Prettyprinter (renderPretty, sepBy, commaSeparated, prettyJSON)

_POLLING_INTERVAL :: Duration
_POLLING_INTERVAL = millis 50
Expand Down
8 changes: 4 additions & 4 deletions src/Ambar/Emulator/Connector/MySQL.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ import Database.MySQL
, withConnection
)
import qualified Database.MySQL as M
import Utils.Delay (Duration, millis, seconds)
import Utils.Async (withAsyncThrow)
import Utils.Logger (SimpleLogger, logDebug, logInfo)
import Utils.Prettyprinter (renderPretty, sepBy, commaSeparated, prettyJSON)
import Util.Delay (Duration, millis, seconds)
import Util.Async (withAsyncThrow)
import Util.Logger (SimpleLogger, logDebug, logInfo)
import Util.Prettyprinter (renderPretty, sepBy, commaSeparated, prettyJSON)

_POLLING_INTERVAL :: Duration
_POLLING_INTERVAL = millis 50
Expand Down
2 changes: 1 addition & 1 deletion src/Ambar/Emulator/Connector/Poll.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import GHC.Generics (Generic)
import Prettyprinter (Pretty, pretty)

import qualified Ambar.Emulator.Queue.Topic as Topic
import Utils.Delay (Duration, delay, fromDiffTime, toDiffTime)
import Util.Delay (Duration, delay, fromDiffTime, toDiffTime)

-- | List of ID ranges to exclude
newtype Boundaries = Boundaries [(EntryId, EntryId)]
Expand Down
8 changes: 4 additions & 4 deletions src/Ambar/Emulator/Connector/Postgres.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import qualified Database.PostgreSQL.Simple.Transaction as P
import qualified Database.PostgreSQL.Simple.FromField as P
import qualified Database.PostgreSQL.Simple.FromRow as P
import GHC.Generics (Generic)
import Utils.Prettyprinter (renderPretty, sepBy, commaSeparated, prettyJSON)
import Util.Prettyprinter (renderPretty, sepBy, commaSeparated, prettyJSON)
import Prettyprinter (pretty, (<+>))
import qualified Prettyprinter as Pretty

Expand All @@ -36,9 +36,9 @@ import Ambar.Emulator.Connector.Poll (BoundaryTracker, Boundaries(..), EntryId(.
import Ambar.Emulator.Queue.Topic (Producer, hashPartitioner)
import Ambar.Record (Record(..), Value(..), Bytes(..), TimeStamp(..))
import qualified Ambar.Record.Encoding as Encoding
import Utils.Async (withAsyncThrow)
import Utils.Delay (Duration, millis, seconds)
import Utils.Logger (SimpleLogger, logDebug, logInfo)
import Util.Async (withAsyncThrow)
import Util.Delay (Duration, millis, seconds)
import Util.Logger (SimpleLogger, logDebug, logInfo)

_POLLING_INTERVAL :: Duration
_POLLING_INTERVAL = millis 50
Expand Down
8 changes: 4 additions & 4 deletions src/Ambar/Emulator/Projector.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ import Ambar.Emulator.Connector.Postgres (PostgreSQL(..))
import Ambar.Emulator.Connector.MySQL (MySQL(..))
import Ambar.Transport (Transport)
import qualified Ambar.Transport as Transport
import Utils.Some (Some)
import Utils.Logger (SimpleLogger, logFatal, logWarn, logInfo, fatal, annotate)
import Utils.Delay (Duration, delay, millis, seconds)
import Utils.Prettyprinter (prettyJSON, renderPretty)
import Util.Some (Some)
import Util.Logger (SimpleLogger, logFatal, logWarn, logInfo, fatal, annotate)
import Util.Delay (Duration, delay, millis, seconds)
import Util.Prettyprinter (prettyJSON, renderPretty)
import Prettyprinter (pretty, fillSep, (<+>))

data Projection = Projection
Expand Down
12 changes: 6 additions & 6 deletions src/Ambar/Emulator/Queue.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ import Ambar.Emulator.Queue.Topic
import qualified Ambar.Emulator.Queue.Topic as T
import qualified Ambar.Emulator.Queue.Partition.File as FilePartition
import Ambar.Emulator.Queue.Partition.File (FilePartition)
import Utils.Async (withAsyncThrow)
import Utils.Delay (every, seconds)
import Utils.Directory (writeAtomically)
import Utils.Some (Some(..))
import Utils.Warden (Warden)
import qualified Utils.Warden as Warden
import Util.Async (withAsyncThrow)
import Util.Delay (every, seconds)
import Util.Directory (writeAtomically)
import Util.Some (Some(..))
import Util.Warden (Warden)
import qualified Util.Warden as Warden

data Queue = Queue
{ q_warden :: Warden
Expand Down
2 changes: 1 addition & 1 deletion src/Ambar/Emulator/Queue/Partition/File.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import System.Directory (doesFileExist, getFileSize, removeFile)
import System.FilePath ((</>))

import Ambar.Emulator.Queue.Partition
import Utils.STM (atomicallyNamed)
import Util.STM (atomicallyNamed)

-- | A file-backed Partition for unformatted JSON entries.
--
Expand Down
6 changes: 3 additions & 3 deletions src/Ambar/Emulator/Queue/Partition/STMReader.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import Ambar.Emulator.Queue.Partition
, Record(..)
, Position(..)
)
import Utils.STM (atomicallyNamed)
import qualified Utils.Warden as Warden
import Utils.Warden (Warden)
import Util.STM (atomicallyNamed)
import qualified Util.Warden as Warden
import Util.Warden (Warden)

import qualified Ambar.Emulator.Queue.Partition as Partition

Expand Down
6 changes: 3 additions & 3 deletions src/Ambar/Emulator/Queue/Topic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ import GHC.Generics (Generic)
import GHC.Stack (HasCallStack)
import System.Random (randomIO)

import Utils.Some (Some(..))
import Utils.STM (atomicallyNamed)
import Utils.Warden (Warden)
import Util.Some (Some(..))
import Util.STM (atomicallyNamed)
import Util.Warden (Warden)

import Ambar.Emulator.Queue.Partition
( Partition
Expand Down
2 changes: 1 addition & 1 deletion src/Ambar/Transport.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Ambar.Transport where
import Data.Text (Text)
import Data.ByteString (ByteString)

import Utils.Some (Some(..))
import Util.Some (Some(..))

-- | A transport is a way to send data to some destination.
class Transport a where
Expand Down
1 change: 1 addition & 0 deletions src/Ambar/Transport/Http.hs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ prettyHttpError httpErr = "*** HTTP Error: " <> case httpErr of
"invalid proxy environment var: " <> var <> ": " <> val
Http.ConnectionClosed -> "connection closed"
Http.InvalidProxySettings _ -> "invalid proxy settings"
Http.TooManyHeaderFields -> "too many header fields"



Expand Down
2 changes: 1 addition & 1 deletion src/Database/MicrosoftSQLServer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import System.IO.Unsafe (unsafePerformIO)
import qualified Database.MSSQLServer.Connection as M
import qualified Database.MSSQLServer.Query as M
import qualified Database.Tds.Message as M
import Utils.Exception (annotateWith)
import Util.Exception (annotateWith)

data ConnectionInfo = ConnectionInfo
{ conn_host :: Text
Expand Down
4 changes: 2 additions & 2 deletions src/Database/MySQL.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ import qualified Database.MySQL.Simple.Result as M (Result(..), ResultError(..))
import qualified Database.MySQL.Simple.QueryResults as M
import qualified Database.MySQL.Simple.QueryParams as M

import Utils.Exception (annotateWith, tryAll)
import Utils.Async (withAsyncBoundThrow)
import Util.Exception (annotateWith, tryAll)
import Util.Async (withAsyncBoundThrow)

query :: (ToRow q, FromRow r) => Connection -> M.Query -> q -> IO [r]
query (Connection run) q params =
Expand Down
2 changes: 1 addition & 1 deletion src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import System.Posix.Signals (installHandler, sigINT, sigTERM, Handler(Catch))

import Ambar.Emulator (emulate)
import Ambar.Emulator.Config (parseEnvConfigFile, EmulatorConfig(..))
import Utils.Logger (plainLogger, Severity(..), logInfo)
import Util.Logger (plainLogger, Severity(..), logInfo)


_DEFAULT_PARTITIONS_PER_TOPIC :: Int
Expand Down
23 changes: 0 additions & 23 deletions src/Utils/Async.hs

This file was deleted.

63 changes: 0 additions & 63 deletions src/Utils/Delay.hs

This file was deleted.

17 changes: 0 additions & 17 deletions src/Utils/Directory.hs

This file was deleted.

Loading

0 comments on commit 421e394

Please sign in to comment.