Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
qbar
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
Container Registry
Model registry
Operate
Environments
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
jktr
qbar
Commits
f5c04253
Commit
f5c04253
authored
5 years ago
by
Jens Nolte
Browse files
Options
Downloads
Patches
Plain Diff
Add new implementation for startPersistentBlockScript using catchP
parent
2b1f2818
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/QBar/Core.hs
+29
-4
29 additions, 4 deletions
src/QBar/Core.hs
with
29 additions
and
4 deletions
src/QBar/Core.hs
+
29
−
4
View file @
f5c04253
...
...
@@ -22,11 +22,12 @@ import qualified Data.Text.Lazy.Encoding as E
import
qualified
Data.Text.Lazy.IO
as
TIO
import
Pipes
import
Pipes.Concurrent
import
Pipes.Safe
(
SafeT
,
runSafeT
)
import
Pipes.Safe
(
SafeT
,
catchP
,
runSafeT
)
import
qualified
Pipes.Prelude
as
PP
import
System.Exit
import
System.IO
import
System.Process.Typed
(
shell
,
withProcessWait
,
setStdin
,
setStdout
,
getStdout
,
closed
,
createPipe
,
readProcessStdout
)
import
System.Process.Typed
(
Process
,
shell
,
setStdin
,
setStdout
,
getStdout
,
closed
,
createPipe
,
withProcessWait
,
readProcessStdout
,
startProcess
,
stopProcess
)
import
Control.Lens
...
...
@@ -237,10 +238,10 @@ blockScript path = forever $ yield . Just =<< (lift blockScriptAction)
createScriptBlock
::
T
.
Text
->
BlockOutput
createScriptBlock
text
=
blockName
?~
T
.
pack
path
$
createBlock
.
pangoText
$
text
startPersistentBlockScript
::
FilePath
->
CachedBlock
startPersistentBlockScript
'
::
FilePath
->
CachedBlock
-- This is only using 'CachedBlock' because the code was already written and tested
-- This could probably be massively simplified by using the new 'pushBlock'
startPersistentBlockScript
path
=
do
startPersistentBlockScript
'
path
=
do
bar
<-
lift
askBar
do
(
output
,
input
,
seal
)
<-
liftIO
$
spawn'
$
latest
$
Nothing
...
...
@@ -276,6 +277,30 @@ startPersistentBlockScript path = do
yield
$
Just
.
createBlock
.
pangoText
$
line
lift
$
updateBar'
bar
startPersistentBlockScript
::
FilePath
->
PushBlock
-- The outer catchP only catches errors that occur during process creation
startPersistentBlockScript
path
=
catchP
startScriptProcess
handleError
where
handleError
::
IOException
->
PushBlock
handleError
e
=
do
yield
.
Just
.
createErrorBlock
$
"["
<>
T
.
pack
(
show
e
)
<>
"]"
return
PushMode
handleErrorWithProcess
::
(
Process
i
o
e
)
->
IOException
->
PushBlock
handleErrorWithProcess
process
e
=
do
stopProcess
process
handleError
e
startScriptProcess
::
PushBlock
startScriptProcess
=
do
let
processConfig
=
setStdin
closed
$
setStdout
createPipe
$
shell
path
process
<-
startProcess
processConfig
-- The inner catchP catches errors that happen after the process has been created
-- This handler will also make sure the process is stopped
catchP
(
blockFromHandle
$
getStdout
process
)
(
handleErrorWithProcess
process
)
blockFromHandle
::
Handle
->
PushBlock
blockFromHandle
handle
=
forever
$
do
line
<-
liftIO
$
TIO
.
hGetLine
handle
yield
$
Just
.
createBlock
.
pangoText
$
line
lift
updateBar
addBlock
::
IsBlock
a
=>
a
->
BarIO
()
addBlock
block
=
do
...
...
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