Skip to content

Commit

Permalink
Bump CLI version, Stack LTS-17.10, MVar -> TVar (#508)
Browse files Browse the repository at this point in the history
  • Loading branch information
expede authored Apr 29, 2021
1 parent dc82350 commit c487282
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 81 deletions.
1 change: 1 addition & 0 deletions .github/workflows/cachix.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches: [main]
jobs:
cachix:
if: false
name: 🖥️ ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
Expand Down
83 changes: 51 additions & 32 deletions fission-cli/library/Fission/CLI/Handler/App/Publish.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import Network.IPFS.CID.Types

import Fission.Prelude

import qualified Fission.Process.Time as Process

import qualified Fission.Web.Client.App as App

import qualified Fission.Internal.UTF8 as UTF8
Expand Down Expand Up @@ -119,13 +117,17 @@ publish
Right _ -> do
ipfsGateway <- getIpfsGateway

when open do
when open do
liftIO . void . openBrowser $ ipfsGateway <> "/" <> show appURL

when watching do
liftIO $ FS.withManager \watchMgr -> do
hashCache <- newMVar hash
timeCache <- newMVar =<< getCurrentTime
now <- getCurrentTime
(hashCache, timeCache) <- atomically do
hashCache <- newTVar hash
timeCache <- newTVar now
return (hashCache, timeCache)

void $ handleTreeChanges runner proof appURL updateData timeCache hashCache watchMgr absBuildPath
forever . liftIO $ threadDelay 1_000_000 -- Sleep main thread

Expand All @@ -145,37 +147,54 @@ handleTreeChanges ::
-> JWT.Proof
-> URL
-> Bool
-> MVar UTCTime
-> MVar Text
-> TVar UTCTime
-> TVar Text
-> WatchManager
-> FilePath -- ^ Build dir
-> IO StopListening
handleTreeChanges runner userProof appURL copyFilesFlag timeCache hashCache watchMgr absDir =
FS.watchTree watchMgr absDir (\_ -> True) \_ -> runner do
now <- getCurrentTime
oldTime <- readMVar timeCache

unless (diffUTCTime now oldTime < Time.doherty) do
void $ swapMVar timeCache now
Process.sleepThread Time.dohertyMicroSeconds

CLI.IPFS.Add.dir absDir >>= \case
Left err ->
CLI.Error.put' err

Right cid@(CID newHash) -> do
oldHash <- swapMVar hashCache newHash
logDebug $ "CID: " <> display oldHash <> " -> " <> display newHash

unless (oldHash == newHash) do
UTF8.putText "\n"
--- req <- App.mkUpdateReq appURL cid copyFilesFlag

req <- App.update appURL cid (Just copyFilesFlag) <$> attachAuth userProof

retryOnStatus [status502] 100 req >>= \case
Left err -> CLI.Error.put err "Server unable to sync data"
Right _ -> success appURL
FS.watchTree watchMgr absDir (\_ -> True) \_ ->
runner do
now <- getCurrentTime

update <- atomically do
oldTime <- readTVar timeCache
if diffUTCTime now oldTime > Time.doherty
then do
writeTVar timeCache now
return True

else
return False

when update do
CLI.IPFS.Add.dir absDir >>= \case
Left err ->
CLI.Error.put' err

Right cid@(CID newHash) -> do
maybeOldHash <- atomically do
oldHash <- readTVar hashCache
if oldHash == newHash
then
return Nothing

else do
writeTVar hashCache newHash
return $ Just oldHash

case maybeOldHash of
Nothing ->
logDebug @Text "CID did not change, noop"

Just oldHash -> do
logDebug $ "CID: " <> display oldHash <> " -> " <> display newHash
UTF8.putNewline
req <- App.update appURL cid (Just copyFilesFlag) <$> attachAuth userProof

retryOnStatus [status502] 100 req >>= \case
Left err -> CLI.Error.put err "Server unable to sync data"
Right _ -> success appURL

success :: MonadIO m => URL -> m ()
success appURL = do
Expand Down
18 changes: 12 additions & 6 deletions fission-cli/library/Fission/CLI/Remote.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@ getRemoteBaseUrl :: MonadRemote m => m BaseUrl
getRemoteBaseUrl = toBaseUrl <$> getRemote

getIpfsGateway :: MonadRemote m => m String
getIpfsGateway = do
url <- getRemoteBaseUrl
let BaseUrl {..} = url
ipfsGateway = url { baseUrlHost = "ipfs." <> baseUrlHost, baseUrlPath = "ipns" }

pure $ showBaseUrl ipfsGateway
getIpfsGateway =
getRemote >>= \case
Production -> fromBase production
Staging -> fromBase staging
LocalDev -> return . showBaseUrl $ BaseUrl Http "localhost" 11235 "ipns"
Custom baseUrl -> fromBase baseUrl
where
fromBase url@BaseUrl{..} =
return $ showBaseUrl url
{ baseUrlHost = "ipfs." <> baseUrlHost
, baseUrlPath = "ipns"
}

getRemoteURL :: MonadRemote m => m URL
getRemoteURL = toURL <$> getRemote
Expand Down
2 changes: 1 addition & 1 deletion fission-cli/package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: fission-cli
version: '2.12.0.0'
version: '2.13.0.0'
category: CLI
author:
- Brooklyn Zelenka
Expand Down
4 changes: 4 additions & 0 deletions fission-core/library/Fission/Internal/UTF8.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Fission.Internal.UTF8
( Textable (..)
, putText
, putTextLn
, putNewline
, displayLazyBS
, toBase58Text
, fromRawBytes
Expand Down Expand Up @@ -126,6 +127,9 @@ putText = Strict.putStr . encodeUtf8
putTextLn :: MonadIO m => Text -> m ()
putTextLn txt = putText $ txt <> "\n"

putNewline :: MonadIO m => m ()
putNewline = putText "\n"

-- | Wrap text with some other piece of text.
wrapIn :: Text -> Text -> Text
wrapIn wrapper txt = wrapper <> txt <> wrapper
Expand Down
11 changes: 4 additions & 7 deletions stack.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
resolver: lts-17.9
resolver: lts-17.10

allow-newer: true

Expand All @@ -11,18 +11,15 @@ packages:

extra-deps:
- amazonka-1.6.1
- constraints-deriving-1.1.1.1
- constraints-deriving-1.1.1.2
- cryptostore-0.2.1.0
- dimensions-2.1.0.0
- dimensions-2.1.1.0
- hfsevents-0.1.6
- ipfs-1.3.0.3
- lzma-clib-5.2.2
- raven-haskell-0.1.4.0
- rescue-0.4.2.1
- servant-auth-0.4.0.0
- servant-auth-server-0.4.6.0
- servant-auth-swagger-0.2.10.1
- servant-swagger-ui-redoc-0.3.3.1.22.3
- servant-swagger-ui-redoc-0.3.4.1.22.3
- servant-websockets-2.0.0
- unliftio-core-0.1.2.0

Expand Down
49 changes: 14 additions & 35 deletions stack.yaml.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ packages:
original:
hackage: amazonka-1.6.1
- completed:
hackage: constraints-deriving-1.1.1.1@sha256:40a239cc58e3d1978590a780736144351d95f0f56232523ade5e145bda1213bb,4064
hackage: constraints-deriving-1.1.1.2@sha256:7e875b19b72920064e30ab722f01a7de2d4ee7840c2889c116297a4549262b72,4027
pantry-tree:
size: 3134
sha256: 401fb63192f1dcb03402def7f4ef05e6da9f001fc7b8024f0fd460680ce75089
size: 3377
sha256: 49c39bb5d120a14f475964b6337288590f12374e94471e6e637c4ca0f5553988
original:
hackage: constraints-deriving-1.1.1.1
hackage: constraints-deriving-1.1.1.2
- completed:
hackage: cryptostore-0.2.1.0@sha256:9896e2984f36a1c8790f057fd5ce3da4cbcaf8aa73eb2d9277916886978c5b19,3881
pantry-tree:
Expand All @@ -26,12 +26,12 @@ packages:
original:
hackage: cryptostore-0.2.1.0
- completed:
hackage: dimensions-2.1.0.0@sha256:c598a801f4ef24d13065a8f6a91b2b0d8f0668623bd4f7a866fa0606fe8b9885,2263
hackage: dimensions-2.1.1.0@sha256:ce33d4765e00e726ae7925f226fc685abd81afc7853cb861b4e04c186e90ad5a,2263
pantry-tree:
size: 1303
sha256: 9ca9bd767a26d86249f85ddeb3df58d3bb1b56b6a1007203d0f2cb34ccedf427
sha256: 5e45ec67acfd851e448db156b7c24859c8447c48f7670080b330c64fc9039a4b
original:
hackage: dimensions-2.1.0.0
hackage: dimensions-2.1.1.0
- completed:
hackage: hfsevents-0.1.6@sha256:295b29e8a4ac51a0015f4fb92b4140139d7b13ed691318159a20f85ce785dac6,863
pantry-tree:
Expand Down Expand Up @@ -68,33 +68,12 @@ packages:
original:
hackage: rescue-0.4.2.1
- completed:
hackage: servant-auth-0.4.0.0@sha256:01d02dfb7df4747fc96442517146d7d4ab0e575e597a124e238e8763036ea4ff,2125
pantry-tree:
size: 332
sha256: a7ec2c54fddfa417ee2467f1131b1d83ad43cc29ddfd4b98869fc924e4b5e980
original:
hackage: servant-auth-0.4.0.0
- completed:
hackage: servant-auth-server-0.4.6.0@sha256:b411b44f4252e91e5da2455d71a7113c8b5b8ff2d943d19b2ddedcfcf0392351,5111
pantry-tree:
size: 1376
sha256: 8cd29612112546a02085e2cb30dd5a72ea46ed81e644195c589d0b26652279cb
original:
hackage: servant-auth-server-0.4.6.0
- completed:
hackage: servant-auth-swagger-0.2.10.1@sha256:6d5f1a4594c922fa8baccb0344de91108d57d1228ec5911723fce4340c27d129,2821
pantry-tree:
size: 408
sha256: b4b12628d1e2ad82c2eb5f09b4074414646104dabad87693b539a109938c5a41
original:
hackage: servant-auth-swagger-0.2.10.1
- completed:
hackage: servant-swagger-ui-redoc-0.3.3.1.22.3@sha256:c3d9d26f66d6e45fe00e401134ffda25a640aeaf9bf469f2964be65cff435fb3,1575
hackage: servant-swagger-ui-redoc-0.3.4.1.22.3@sha256:c19967101d9205b1a936fad254f22f02c471953c10b1137364a4589e121f0562,1474
pantry-tree:
size: 381
sha256: c66e48f90cd9e6beda31ecfa8b2761c02ff3a4b6373638578202048e8c7cf6a1
sha256: 854dc59f86a3d1c30f48c9be287dcba7dbdaf482f4488d8d94884ff577678cc3
original:
hackage: servant-swagger-ui-redoc-0.3.3.1.22.3
hackage: servant-swagger-ui-redoc-0.3.4.1.22.3
- completed:
hackage: servant-websockets-2.0.0@sha256:6e9e3600bced90fd52ed3d1bf632205cb21479075b20d6637153cc4567000234,2253
pantry-tree:
Expand All @@ -111,7 +90,7 @@ packages:
hackage: unliftio-core-0.1.2.0
snapshots:
- completed:
size: 567037
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/17/9.yaml
sha256: d7d8d5106e53d1669964bd8bd2b0f88a5ad192d772f5376384b76738fd992311
original: lts-17.9
size: 567241
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/17/10.yaml
sha256: 321b3b9f0c7f76994b39e0dabafdc76478274b4ff74cc5e43d410897a335ad3b
original: lts-17.10

0 comments on commit c487282

Please sign in to comment.