[refactor] remove redundant typeslass constraints

This review commit removes a bunch of redundant typeclass constraints,
especially the ones on the data declarations, generally considered a
codesmell.
parent 6da18f77
......@@ -154,8 +154,7 @@ handleMessage state@(State { .. }) brokerMessage = do
-- )
callWorkerJobEvent :: (HasWorkerBroker b a)
=> WorkerJobEvent b a
callWorkerJobEvent :: WorkerJobEvent b a
-> State b a
-> BrokerMessage b (Job a)
-> IO ()
......@@ -223,7 +222,7 @@ handleJobError _state@(State { .. }) brokerMessage = do
void $ sendJob broker queueName (job { metadata = mdata { readCount = readCt + 1 } })
handleUnknownError :: (HasWorkerBroker b a) => State b a -> SomeException -> IO ()
handleUnknownError :: State b a -> SomeException -> IO ()
handleUnknownError state err = do
let _ = traceStack ("unknown error: " <> show err)
putStrLn $ formatStr state $ "unknown error: " <> show err
......@@ -242,7 +241,7 @@ microsecond = 10^(6 :: Int)
-}
-- | Wraps parameters for the 'sendJob' function
data (HasWorkerBroker b a) => SendJob b a =
data SendJob b a =
SendJob { broker :: Broker b (Job a)
, queue :: Queue
, msg :: a
......@@ -254,8 +253,7 @@ data (HasWorkerBroker b a) => SendJob b a =
, resendOnKill :: Bool}
-- | Create a 'SendJob' data with some defaults
mkDefaultSendJob :: HasWorkerBroker b a
=> Broker b (Job a)
mkDefaultSendJob :: Broker b (Job a)
-> Queue
-> a
-> Timeout
......@@ -276,8 +274,7 @@ mkDefaultSendJob broker queue msg timeout =
-- | Like 'mkDefaultSendJob' but with default timeout
mkDefaultSendJob' :: HasWorkerBroker b a
=> Broker b (Job a)
mkDefaultSendJob' :: Broker b (Job a)
-> Queue
-> a
-> SendJob b a
......
......@@ -238,7 +238,7 @@ jobTimeout (Job { metadata }) = timeout metadata
--
-- Note that our underlying 'Broker' handles messages of type 'Job'
-- 'a'.
data (HasWorkerBroker b a) => State b a =
data State b a =
State { broker :: Broker b (Job a)
-- | Queue associated with this worker. If you want to support
-- more queues, spawn more workers.
......@@ -259,7 +259,7 @@ data (HasWorkerBroker b a) => State b a =
-- | Helper function to call an action for given worker, for a
-- 'BrokerMessage'.
runAction :: (HasWorkerBroker b a) => State b a -> BrokerMessage b (Job a) -> IO ()
runAction :: State b a -> BrokerMessage b (Job a) -> IO ()
runAction state brokerMessage = (performAction state) state brokerMessage
type WorkerJobEvent b a = Maybe (State b a -> BrokerMessage b (Job a) -> IO ())
......@@ -274,7 +274,7 @@ type PerformAction b a =
type HasWorkerBroker b a = ( MessageBroker b (Job a), Typeable a, Typeable b, Show a )
-- | Helper function to format a string with worker name (for logging)
formatStr :: (HasWorkerBroker b a) => State b a -> String -> String
formatStr :: State b a -> String -> String
formatStr (State { name }) msg =
"[" <> name <> "] " <> msg
......@@ -282,5 +282,5 @@ formatStr (State { name }) msg =
data JobTimeout b a =
JobTimeout { jtBMessage :: BrokerMessage b (Job a)
, jtTimeout :: Timeout }
deriving instance (HasWorkerBroker b a) => Show (JobTimeout b a)
instance (HasWorkerBroker b a) => Exception (JobTimeout b a)
deriving instance (Show (BrokerMessage b (Job a))) => Show (JobTimeout b a)
instance (Show (BrokerMessage b (Job a)), Typeable a, Typeable b) => Exception (JobTimeout b a)
......@@ -112,7 +112,7 @@ waitUntilTVarEq tvar expected (TimeoutMs timeoutMs) = do
performTest
-- | Similar to 'waitUntilTVarEq' but with predicate checking
waitUntilTVarPred :: (HasCallStack, Show a, Eq a) => TVar a -> (a -> Bool) -> TimeoutMs -> Expectation
waitUntilTVarPred :: (HasCallStack, Show a) => TVar a -> (a -> Bool) -> TimeoutMs -> Expectation
waitUntilTVarPred tvar predicate (TimeoutMs timeoutMs) = do
_mTimeout <- Timeout.timeout (timeoutMs * 1000) performTest
-- shortcut for testing mTimeout
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment