Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Christian Merten
haskell-gargantext
Commits
2611bbae
Unverified
Commit
2611bbae
authored
Feb 19, 2019
by
Nicolas Pouillard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[NGRAMS-REPO] add file locking
parent
4ddc86ca
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
3 deletions
+15
-3
package.yaml
package.yaml
+1
-0
Ngrams.hs
src/Gargantext/API/Ngrams.hs
+2
-0
Settings.hs
src/Gargantext/API/Settings.hs
+12
-3
No files found.
package.yaml
View file @
2611bbae
...
...
@@ -99,6 +99,7 @@ library:
-
fullstop
-
fclabels
-
fast-logger
-
filelock
-
full-text-search
-
http-client
-
http-client-tls
...
...
src/Gargantext/API/Ngrams.hs
View file @
2611bbae
...
...
@@ -82,6 +82,7 @@ import Gargantext.Prelude
-- import Gargantext.Core.Types (ListTypeId, listTypeId)
import
Gargantext.Core.Types
(
ListType
(
..
),
NodeId
,
ListId
,
CorpusId
,
Limit
,
Offset
)
import
Servant
hiding
(
Patch
)
import
System.FileLock
(
FileLock
)
import
Test.QuickCheck
(
elements
)
import
Test.QuickCheck.Arbitrary
(
Arbitrary
,
arbitrary
)
...
...
@@ -604,6 +605,7 @@ initMockRepo = Repo 1 s []
data
RepoEnv
=
RepoEnv
{
_renv_var
::
!
(
MVar
NgramsRepo
)
,
_renv_saver
::
!
(
IO
()
)
,
_renv_lock
::
!
FileLock
}
deriving
(
Generic
)
...
...
src/Gargantext/API/Settings.hs
View file @
2611bbae
...
...
@@ -32,6 +32,7 @@ import Prelude (Bounded(), fail)
import
System.Environment
(
lookupEnv
)
import
System.IO
(
FilePath
,
hClose
)
import
System.IO.Temp
(
withTempFile
)
import
System.FileLock
(
tryLockFile
,
unlockFile
,
SharedExclusive
(
Exclusive
))
import
Database.PostgreSQL.Simple
(
Connection
,
connect
)
import
Network.HTTP.Client
(
Manager
)
import
Network.HTTP.Client.TLS
(
newTlsManager
)
...
...
@@ -60,7 +61,7 @@ import Control.Monad.Reader
import
Control.Lens
import
Gargantext.Prelude
import
Gargantext.Database.Utils
(
databaseParameters
,
HasConnection
(
..
),
Cmd
'
,
runCmd
)
import
Gargantext.API.Ngrams
(
NgramsRepo
,
HasRepoVar
(
..
),
HasRepoSaver
(
..
),
HasRepo
(
..
),
RepoEnv
(
..
),
r_version
,
saveRepo
,
initRepo
)
import
Gargantext.API.Ngrams
(
NgramsRepo
,
HasRepoVar
(
..
),
HasRepoSaver
(
..
),
HasRepo
(
..
),
RepoEnv
(
..
),
r_version
,
saveRepo
,
initRepo
,
renv_lock
)
import
Gargantext.API.Orchestrator.Types
type
PortNumber
=
Int
...
...
@@ -197,6 +198,9 @@ readRepoEnv = do
then
(
>
0
)
<$>
getFileSize
repoSnapshot
else
pure
False
mlock
<-
tryLockFile
repoSnapshot
Exclusive
lock
<-
maybe
(
panic
"Repo file already locked"
)
pure
mlock
mvar
<-
newMVar
=<<
if
repoExists
then
do
...
...
@@ -209,7 +213,7 @@ readRepoEnv = do
pure
initRepo
saver
<-
mkRepoSaver
mvar
pure
$
RepoEnv
{
_renv_var
=
mvar
,
_renv_saver
=
saver
}
pure
$
RepoEnv
{
_renv_var
=
mvar
,
_renv_saver
=
saver
,
_renv_lock
=
lock
}
newEnv
::
PortNumber
->
FilePath
->
IO
Env
newEnv
port
file
=
do
...
...
@@ -264,9 +268,14 @@ newDevEnvWith file = do
,
_dev_env_repo
=
repo
}
withDevEnv
::
(
DevEnv
->
IO
a
)
->
IO
a
withDevEnv
k
=
do
env
<-
newDevEnv
k
env
`
finally
`
unlockFile
(
env
^.
repoEnv
.
renv_lock
)
-- | Run Cmd Sugar for the Repl (GHCI)
runCmdRepl
::
Show
err
=>
Cmd'
DevEnv
err
a
->
IO
a
runCmdRepl
f
=
newDevEnv
>>=
\
env
->
runCmdDev
env
f
runCmdRepl
f
=
withDevEnv
$
\
env
->
runCmdDev
env
f
newDevEnv
::
IO
DevEnv
newDevEnv
=
newDevEnvWith
"gargantext.ini"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment