Skip to content

Commit

Permalink
Get galley to compile.
Browse files Browse the repository at this point in the history
  • Loading branch information
fisx committed Oct 2, 2024
1 parent 2974f24 commit 8a1840d
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 24 deletions.
3 changes: 1 addition & 2 deletions services/brig/src/Brig/CanonicalInterpreter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ import Control.Monad.Catch (throwM)
import Data.Qualified (Local, toLocalUnsafe)
import Data.Time.Clock (UTCTime, getCurrentTime)
import Imports
import Network.AMQP
import Network.AMQP qualified as Q
import Network.AMQP as Q
import Polysemy
import Polysemy.Async
import Polysemy.Conc
Expand Down
10 changes: 5 additions & 5 deletions services/galley/src/Galley/App.hs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ import Galley.Queue qualified as Q
import Galley.Types.Teams
import HTTP2.Client.Manager (Http2Manager, http2ManagerWithSSLCtx)
import Imports hiding (forkIO)
import Network.AMQP qualified as AMQP
import Network.AMQP.Extended (mkRabbitMqChannelMVar)
import Network.HTTP.Client (responseTimeoutMicro)
import Network.HTTP.Client.OpenSSL
Expand All @@ -102,6 +103,7 @@ import Ssl.Util
import System.Logger qualified as Log
import System.Logger.Class (Logger)
import System.Logger.Extended qualified as Logger
import System.Timeout qualified
import UnliftIO.Exception qualified as UnliftIO
import Wire.API.Conversation.Protocol
import Wire.API.Error
Expand All @@ -118,6 +120,7 @@ import Wire.Sem.Random.IO
type GalleyEffects0 =
'[ Input ClientState,
Input Env,
Input AMQP.Channel,
Error InvalidInput,
Error InternalError,
-- federation errors can be thrown by almost every endpoint, so we avoid
Expand All @@ -143,10 +146,6 @@ validateOptions o = do
error "setMaxConvSize cannot be > setTruncationLimit"
when (settings' ^. maxTeamSize < optFanoutLimit) $
error "setMaxTeamSize cannot be < setTruncationLimit"
case (o ^. O.federator, o ^. rabbitmq) of
(Nothing, Just _) -> error "RabbitMQ config is specified and federator is not, please specify both or none"
(Just _, Nothing) -> error "Federator is specified and RabbitMQ config is not, please specify both or none"
_ -> pure ()
let mlsFlag = settings' ^. featureFlags . to (featureDefaults @MLSConfig)
mlsConfig = mlsFlag.config
migrationStatus = (.status) $ settings' ^. featureFlags . to (featureDefaults @MlsMigrationConfig)
Expand All @@ -172,7 +171,7 @@ createEnv o l = do
<*> initExtEnv
<*> maybe (pure Nothing) (fmap Just . Aws.mkEnv l mgr) (o ^. journal)
<*> traverse loadAllMLSKeys (o ^. settings . mlsPrivateKeyPaths)
<*> traverse (mkRabbitMqChannelMVar l) (o ^. rabbitmq)
<*> mkRabbitMqChannelMVar l (o ^. rabbitmq)
<*> pure codeURIcfg

initCassandra :: Opts -> Logger -> IO ClientState
Expand Down Expand Up @@ -251,6 +250,7 @@ evalGalley e =
. mapError toResponse
. mapError toResponse
. mapError toResponse
. runInputSem (embed $ fromMaybe (error "TODO: no rabbitmq channel in Env") <$> System.Timeout.timeout 1_000_000 (readMVar @IO e._rabbitmqChannel))
. runInputConst e
. runInputConst (e ^. cstate)
. mapError toResponse -- DynError
Expand Down
2 changes: 1 addition & 1 deletion services/galley/src/Galley/Env.hs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ data Env = Env
_extEnv :: ExtEnv,
_aEnv :: Maybe Aws.Env,
_mlsKeys :: Maybe (MLSKeysByPurpose MLSPrivateKeys),
_rabbitmqChannel :: Maybe (MVar Q.Channel),
_rabbitmqChannel :: MVar Q.Channel,
_convCodeURI :: Either HttpsUrl (Map Text HttpsUrl)
}

Expand Down
7 changes: 2 additions & 5 deletions services/galley/src/Galley/Intra/BackendNotificationQueue.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ interpretBackendNotificationQueueAccess = interpret $ \case
logEffect "BackendNotificationQueueAccess.EnqueueNotificationsConcurrentlyBuckets"
embedApp . runExceptT $ enqueueNotificationsConcurrentlyBuckets m xs rpc

getChannel :: ExceptT FederationError App (MVar Q.Channel)
getChannel = view rabbitmqChannel >>= maybe (throwE FederationNotConfigured) pure

enqueueSingleNotification :: Domain -> Q.DeliveryMode -> MVar Q.Channel -> FedQueueClient c a -> App a
enqueueSingleNotification remoteDomain deliveryMode chanVar action = do
ownDomain <- view (options . settings . federationDomain)
Expand Down Expand Up @@ -71,7 +68,7 @@ enqueueSingleNotification remoteDomain deliveryMode chanVar action = do

enqueueNotification :: Q.DeliveryMode -> Domain -> FedQueueClient c a -> ExceptT FederationError App a
enqueueNotification deliveryMode remoteDomain action = do
chanVar <- getChannel
chanVar <- view rabbitmqChannel
lift $ enqueueSingleNotification remoteDomain deliveryMode chanVar action

enqueueNotificationsConcurrently ::
Expand All @@ -94,7 +91,7 @@ enqueueNotificationsConcurrentlyBuckets m xs f = do
-- only attempt to get a channel if there is at least one notification to send
[] -> pure []
_ -> do
chanVar <- getChannel
chanVar <- view rabbitmqChannel
lift $ pooledForConcurrentlyN 8 (toList xs) $ \r ->
qualifyAs r
<$> enqueueSingleNotification (tDomain r) m chanVar (f r)
Expand Down
4 changes: 2 additions & 2 deletions services/galley/src/Galley/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ data Opts = Opts
_spar :: !Endpoint,
-- | Federator endpoint
_federator :: !(Maybe Endpoint),
-- | RabbitMQ settings, required when federation is enabled.
_rabbitmq :: !(Maybe AmqpEndpoint),
-- | RabbitMQ settings
_rabbitmq :: !AmqpEndpoint,
-- | Disco URL
_discoUrl :: !(Maybe Text),
-- | Other settings
Expand Down
12 changes: 3 additions & 9 deletions services/galley/test/integration/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ import Data.Time.Clock (getCurrentTime)
import Federator.Discovery (DiscoveryFailure (..))
import Federator.MockServer
import Galley.API.Mapping
import Galley.Options (federator, rabbitmq)
import Galley.Options (federator)
import Galley.Types.Conversations.Members
import Imports hiding (id)
import Imports qualified as I
Expand Down Expand Up @@ -1902,10 +1902,7 @@ postConvQualifiedFederationNotEnabled = do
let domain = Domain "some-remote-backend.example.com"
bob <- flip Qualified domain <$> randomId
connectWithRemoteUser alice bob
let federatorNotConfigured o =
o
& federator .~ Nothing
& rabbitmq .~ Nothing
let federatorNotConfigured = federator .~ Nothing
withSettingsOverrides federatorNotConfigured $ do
g <- viewGalley
unreachable :: UnreachableBackends <-
Expand Down Expand Up @@ -2360,10 +2357,7 @@ testAddRemoteMemberFederationDisabled = do

-- federator endpoint not configured is equivalent to federation being disabled
-- This is the case on staging/production in May 2021.
let federatorNotConfigured o =
o
& federator .~ Nothing
& rabbitmq .~ Nothing
let federatorNotConfigured = federator .~ Nothing
withSettingsOverrides federatorNotConfigured $
postQualifiedMembers alice (remoteBob :| []) qconvId !!! do
const 400 === statusCode
Expand Down

0 comments on commit 8a1840d

Please sign in to comment.