Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
walint
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
hub
walint
Commits
508da680
Commit
508da680
authored
3 years ago
by
stuebinm
Browse files
Options
Downloads
Patches
Plain Diff
mapserver: somewhat more decent logging
parent
e5adcba7
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
package.yaml
+1
-0
1 addition, 0 deletions
package.yaml
server/Main.hs
+7
-9
7 additions, 9 deletions
server/Main.hs
server/Worker.hs
+23
-18
23 additions, 18 deletions
server/Worker.hs
walint.cabal
+1
-0
1 addition, 0 deletions
walint.cabal
with
32 additions
and
27 deletions
package.yaml
+
1
−
0
View file @
508da680
...
@@ -96,6 +96,7 @@ executables:
...
@@ -96,6 +96,7 @@ executables:
-
warp
-
warp
-
wai
-
wai
-
wai-extra
-
wai-extra
-
monad-logger
-
lucid
-
lucid
-
servant
-
servant
-
servant-server
-
servant-server
...
...
This diff is collapsed.
Click to expand it.
server/Main.hs
+
7
−
9
View file @
508da680
...
@@ -49,6 +49,7 @@ import Worker (Job (Job), linterThread)
...
@@ -49,6 +49,7 @@ import Worker (Job (Job), linterThread)
import
Servant.API
(
Header
)
import
Servant.API
(
Header
)
import
Servant.Client
(
ClientM
,
client
,
import
Servant.Client
(
ClientM
,
client
,
mkClientEnv
,
runClientM
)
mkClientEnv
,
runClientM
)
import
Control.Monad.Logger
(
logInfoN
,
runStdoutLoggingT
)
type
family
PolyEndpoint
method
format
payload
where
type
family
PolyEndpoint
method
format
payload
where
PolyEndpoint
Get
format
payload
=
PolyEndpoint
Get
format
payload
=
...
@@ -94,8 +95,6 @@ main = do
...
@@ -94,8 +95,6 @@ main = do
config
<-
loadConfig
"./config.toml"
config
<-
loadConfig
"./config.toml"
state
<-
newMVar
(
emptyState
config
)
state
<-
newMVar
(
emptyState
config
)
queue
::
TQueue
Job
<-
newTQueueIO
queue
::
TQueue
Job
<-
newTQueueIO
-- TODO: i really don't like all this cli logging stuff, replace it with
-- fast-logger at some point …
loggerMiddleware
<-
mkRequestLogger
loggerMiddleware
<-
mkRequestLogger
$
def
{
outputFormat
=
Detailed
(
view
verbose
config
)
}
$
def
{
outputFormat
=
Detailed
(
view
verbose
config
)
}
...
@@ -104,8 +103,6 @@ main = do
...
@@ -104,8 +103,6 @@ main = do
-- periodically ‘pokes’ jobs to re-lint each repo
-- periodically ‘pokes’ jobs to re-lint each repo
poker
<-
async
$
forever
$
do
poker
<-
async
$
forever
$
do
readMVar
state
>>=
\
state
->
print
(
length
$
view
unState
state
)
atomically
$
forM_
(
view
orgs
config
)
$
\
org
->
atomically
$
forM_
(
view
orgs
config
)
$
\
org
->
forM_
(
orgRepos
org
)
$
\
repo
->
forM_
(
orgRepos
org
)
$
\
repo
->
writeTQueue
queue
(
Job
repo
org
)
writeTQueue
queue
(
Job
repo
org
)
...
@@ -115,13 +112,13 @@ main = do
...
@@ -115,13 +112,13 @@ main = do
-- TODO: what about tls / https?
-- TODO: what about tls / https?
whenJust
(
view
exneuland
config
)
$
\
baseurl
->
do
whenJust
(
view
exneuland
config
)
$
\
baseurl
->
do
manager'
<-
newManager
defaultManagerSettings
manager'
<-
newManager
defaultManagerSettings
updater
<-
async
$
forever
$
do
updater
<-
async
$
runStdoutLoggingT
$
forever
$
do
done
<-
readMVar
state
done
<-
readMVar
state
res
<-
runClientM
res
<-
liftIO
$
runClientM
(
postNewMaps
(
view
token
config
)
(
MapService
done
))
(
postNewMaps
(
view
token
config
)
(
MapService
done
))
(
mkClientEnv
manager'
baseurl
)
(
mkClientEnv
manager'
baseurl
)
print
res
logInfoN
$
"exneuland maps POST request: "
<>
show
res
threadDelay
(
view
interval
config
*
1000000
)
liftIO
$
threadDelay
(
view
interval
config
*
1000000
)
link
updater
link
updater
-- spawns threads for each job in the queue
-- spawns threads for each job in the queue
...
@@ -133,6 +130,7 @@ main = do
...
@@ -133,6 +130,7 @@ main = do
setPort
(
view
port
config
)
setPort
(
view
port
config
)
defaultSettings
defaultSettings
putTextLn
$
"starting server on port "
<>
show
(
view
port
config
)
runSettings
warpsettings
runSettings
warpsettings
.
loggerMiddleware
.
loggerMiddleware
$
app
state
$
app
state
...
@@ -140,4 +138,4 @@ main = do
...
@@ -140,4 +138,4 @@ main = do
waitEither_
linter
poker
waitEither_
linter
poker
where
where
showInfo
org
=
showInfo
org
=
"→ org "
+|
orgSlug
org
|+
"
divoc
("
+|
length
(
orgRepos
org
)
|+
" repositor
y
ies)
\n
"
::
Text
"→ org "
+|
orgSlug
org
|+
" ("
+|
length
(
orgRepos
org
)
|+
" repositories)
\n
"
::
Text
This diff is collapsed.
Click to expand it.
server/Worker.hs
+
23
−
18
View file @
508da680
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
module
Worker
(
linterThread
,
Job
(
..
))
where
module
Worker
(
linterThread
,
Job
(
..
))
where
...
@@ -23,10 +24,12 @@ import Server (Config, JobStatus (..),
...
@@ -23,10 +24,12 @@ import Server (Config, JobStatus (..),
ServerState
,
adjustedPath
,
ServerState
,
adjustedPath
,
setJobStatus
,
tmpdir
)
setJobStatus
,
tmpdir
)
import
System.Directory
(
doesDirectoryExist
)
import
System.Directory
(
doesDirectoryExist
)
import
System.Exit
(
ExitCode
(
ExitFailure
))
import
System.Exit
(
ExitCode
(
ExitFailure
,
ExitSuccess
))
import
System.FilePath
((
</>
))
import
System.FilePath
((
</>
))
import
System.Process
import
System.Process
import
WriteRepo
(
writeAdjustedRepository
)
import
WriteRepo
(
writeAdjustedRepository
)
import
Control.Monad.Logger
(
runStdoutLoggingT
,
logErrorN
,
logInfoN
,
logError
)
import
Fmt
((
+|
),
(
|+
))
data
Job
=
Job
data
Job
=
Job
{
jobRef
::
RemoteRef
{
jobRef
::
RemoteRef
...
@@ -65,34 +68,36 @@ runJob config Job {..} done = do
...
@@ -65,34 +68,36 @@ runJob config Job {..} done = do
,
"--depth"
,
"1"
,
"-b"
,
toString
ref
])
,
"--depth"
,
"1"
,
"-b"
,
toString
ref
])
rev
<-
map
T
.
strip
-- git returns a newline here
rev
<-
map
T
.
strip
-- git returns a newline here
$
readgit'
gitdir
[
"rev-parse"
,
toString
ref
]
$
readgit'
gitdir
[
"rev-parse"
,
toString
ref
]
let
outPath
=
adjustedPath
rev
jobOrg
callgit
gitdir
[
"worktree"
,
"add"
,
"--force"
,
workdir
,
toString
ref
]
callgit
gitdir
[
"worktree"
,
"add"
,
"--force"
,
workdir
,
toString
ref
]
res
<-
recursiveCheckDir
(
orgLintconfig
jobOrg
)
workdir
(
orgEntrypoint
jobOrg
)
res
<-
recursiveCheckDir
(
orgLintconfig
jobOrg
)
workdir
(
orgEntrypoint
jobOrg
)
>>=
evaluateNF
>>=
evaluateNF
writeAdjustedRepository
(
orgLintconfig
jobOrg
)
workdir
(
toString
$
adjustedPath
rev
jobOrg
)
res
writeAdjustedRepository
(
orgLintconfig
jobOrg
)
workdir
(
toString
outPath
)
res
>>=
\
case
ExitFailure
1
->
>>=
runStdoutLoggingT
.
\
case
-- error's in the result anyways
ExitSuccess
->
pure
()
logInfoN
$
"linted map "
+|
(
show
jobRef
::
Text
)
|+
"."
ExitFailure
1
->
logInfoN
$
"linted map "
+|
(
show
jobRef
::
Text
)
|+
", which failed."
ExitFailure
2
->
ExitFailure
2
->
-- TODO: use a fastlogger for this or sth
-- TODO: shouldn't have linted this map at all
-- TODO: shouldn't have linted this map at all
putTextLn
"ERROR: outpath already exists"
logErrorN
$
"outpath "
+|
outPath
|+
" already exists!"
ExitFailure
n
->
do
-- impossible
ExitFailure
_
->
print
n
-- writeAdjustedRepository does not return other codes
pure
()
$
(
logError
)
"wtf, this is impossible"
_
->
pure
()
-- all good
putTextLn
"still here!"
setJobStatus
done
jobOrg
jobRef
$
setJobStatus
done
jobOrg
jobRef
$
Linted
(
shrinkDirResult
res
)
rev
Linted
(
shrinkDirResult
res
)
rev
cleanup
workdir
=
do
cleanup
workdir
=
do
callgit
gitdir
[
"worktree"
,
"remove"
,
"-f"
,
"-f"
,
workdir
]
callgit
gitdir
[
"worktree"
,
"remove"
,
"-f"
,
"-f"
,
workdir
]
whoops
(
error
::
IOException
)
=
do
whoops
(
error
::
IOException
)
=
runStdoutLoggingT
$
do
-- TODO: should also log this
error
logErrorN
(
show
error
)
setJobStatus
done
jobOrg
jobRef
$
Failed
(
show
error
)
liftIO
$
setJobStatus
done
jobOrg
jobRef
$
Failed
(
show
error
)
url
=
repourl
jobRef
url
=
repourl
jobRef
ref
=
reporef
jobRef
ref
=
reporef
jobRef
...
...
This diff is collapsed.
Click to expand it.
walint.cabal
+
1
−
0
View file @
508da680
...
@@ -166,6 +166,7 @@ executable walint-mapserver
...
@@ -166,6 +166,7 @@ executable walint-mapserver
, http-types
, http-types
, lucid
, lucid
, microlens-platform
, microlens-platform
, monad-logger
, process
, process
, servant
, servant
, servant-client
, servant-client
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment