Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {-# OPTIONS_GHC -fno-warn-unused-imports #-}
- {-# OPTIONS_GHC -fno-warn-unused-binds #-}
- {-# OPTIONS_GHC -fno-warn-missing-signatures #-}
- {-# OPTIONS_GHC -fno-warn-name-shadowing #-}
- {-# LANGUAGE OverloadedStrings #-}
- module DebugMain where
- import Rapid
- import Debug.Trace
- import System.FilePath
- import Control.Monad (replicateM_, forM_)
- import Control.Monad.IO.Class (MonadIO, liftIO)
- import Control.Lens ((&), (?~), (^.), (.~))
- import Data.Text (Text)
- import Data.Monoid ((<>))
- import qualified Data.Aeson as A
- import qualified Vertigo.Types.Notification.Ids as N
- import qualified Vertigo.Types.Notification as N
- import qualified Vertigo.Types.Notification.UserCore as N
- import qualified Vertigo.Types.Settings.UserSettings as US
- import qualified Vertigo.Dsl.Db as DB
- import Vertigo.Ext
- import Vertigo.Dsl.Functors (NotifyFree)
- import Vertigo.Dsl.Operations
- import Vertigo.Dsl.RunProd
- import Vertigo.Dsl.Db
- import Vertigo.Types.DeviceInfo
- import Vertigo.AppM
- import Vertigo.Web.Admin
- import System.IO.Unsafe -- haha =)
- import Vertigo.Types.VUUID
- import Vertigo.Types.Settings.UserSettings (UserSettings)
- import Vertigo.Types.Settings.GlobalSettings (GlobalSettings, Origin(..))
- import Vertigo.Types.Settings.GlobalSettingsDelta
- import Vertigo.Logic.Settings
- update :: IO ()
- update =
- rapid 0 $ \_r ->
- -- We'll list our components here shortly.
- -- ext <- createRef r ("ext" :: String) buildEnvironmentExt
- -- let cp = ext ^. pool
- -- runAppIO ext $ runProd $ dbInsertSettings uid settings
- -- mbUs <- runAppIO ext $ runProd $ dbReadSettings uid
- -- putStrLn $ "mbUs = " <> show mbUs
- pure()
- {-# NOINLINE ext #-}
- ext = unsafePerformIO buildEnvironmentExt
- rid = N.ReceiverId uid
- txt = "Oh, yea!" :: Text
- fid = N.FollowerId "6a2cd69e-b7f4-4467-952f-ecb585f9509c"
- uname = N.UserName "westcoastjim"
- nt = N.NewFollower N.NewFollowerArg
- ntf = N.Notification rid
- uid = N.UserId "6a2cd69e-b7f4-4467-952f-ecb585f9509e"
- did = DeviceId "0de5aa77-9bc5-41e7-be4f-c6df1b102ef7"
- endpointArn = EndpointArn "arn:aws:sns:us-west-2:877422789438:endpoint/APNS_SANDBOX/com-vertigomediagroup-mobile-dev-apns-sandbox/5aadfd17-7cff-3493-b330-4961809f9deb"
- msg = "Free monads will blow your mind" :: Text
- device = DeviceInfo
- { _diOperatingSystem = "ios"
- , _diDeviceModel = "iPhone 6 Plus"
- , _diManufacturer = "Apple"
- , _diOsVersion = "9.2.1"
- , _diDeviceId = did
- , _diNotificationEnabled = True
- , _diNotificationToken = DeviceToken "86f48fc27cc72ef86f0d06f24645d50668422ed28655f29f523e2f701e891279"
- , _diSnsEndpointArn = Nothing
- }
- gs :: GlobalSettings
- gs = makeGlobalSettings $ mempty
- & newLiveSession .~ Just True
- & mentionInPost .~ Just Everyone
- & mentionInComment .~ Nothing
- & newFollower .~ Just True
- & commentOnPost .~ Just Following
- & likeOnPost .~ Nothing
- gsd :: GlobalSettingsDelta
- gsd = mempty & newLiveSession .~ Just False
- kick1 :: IO GlobalSettings
- --kick = runAppIO ext $ runProd $ dbReadSettings uid
- kick1 = runAppIO ext $ runProd $ getGlobalSettings uid
- kick2 :: IO ()
- kick2 = runAppIO ext $ runProd $ postGlobalSettings uid gsd
- kick3 :: IO ()
- kick3 = replicateM_ 10 $ runAppIO ext $ runProd $ rollbackTest uid gsd
- uids =
- [ N.UserId "0a2cd69e-b7f4-4467-952f-ecb585f9509e"
- , N.UserId "1a2cd69e-b7f4-4467-952f-ecb585f9509e"
- , N.UserId "2a2cd69e-b7f4-4467-952f-ecb585f9509e"
- , N.UserId "3a2cd69e-b7f4-4467-952f-ecb585f9509e"
- , N.UserId "4a2cd69e-b7f4-4467-952f-ecb585f9509e"
- , N.UserId "5a2cd69e-b7f4-4467-952f-ecb585f9509e"
- , N.UserId "6a2cd69e-b7f4-4467-952f-ecb585f9509e"
- , N.UserId "7a2cd69e-b7f4-4467-952f-ecb585f9509e"
- , N.UserId "8a2cd69e-b7f4-4467-952f-ecb585f9509e"
- , N.UserId "9a2cd69e-b7f4-4467-952f-ecb585f9509e"
- ]
- rollbackTest :: N.UserId -> GlobalSettingsDelta -> NotifyFree ()
- rollbackTest _uid delta = do
- let us = US.UserSettings US.globalVersion delta []
- r <- dbTransaction $ do
- -- us' <- DB.getUserSettings [uid]
- forM_ uids $ \u -> DB.insertUserSettings u us
- traceM "abort DB.rollback"
- DB.rollback
- let x = N.UserId "00000000-b7f4-4467-952f-ecb585f9509e"
- traceM $ "r = " <> show r
- s <- dbTransaction $
- DB.insertUserSettings x us
- traceM $ "s = " <> show s
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement