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
Jens Nolte
qbar
Commits
debd83a3
Commit
debd83a3
authored
4 years ago
by
jktr
Browse files
Options
Downloads
Patches
Plain Diff
Add support for specifying script block poll interval
parent
2eec2e41
No related branches found
No related tags found
1 merge request
!6
Add support for specifying script block poll interval
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/QBar/Blocks/Script.hs
+3
-2
3 additions, 2 deletions
src/QBar/Blocks/Script.hs
src/QBar/Cli.hs
+13
-2
13 additions, 2 deletions
src/QBar/Cli.hs
src/QBar/Time.hs
+4
-1
4 additions, 1 deletion
src/QBar/Time.hs
with
20 additions
and
5 deletions
src/QBar/Blocks/Script.hs
+
3
−
2
View file @
debd83a3
...
...
@@ -4,6 +4,7 @@ import QBar.BlockHelper
import
QBar.BlockOutput
import
QBar.Core
import
QBar.TagParser
import
QBar.Time
import
Control.Exception
(
IOException
)
import
qualified
Data.ByteString.Lazy.Char8
as
C8
...
...
@@ -18,8 +19,8 @@ import System.Process.Typed (Process, shell, setStdin, setStdout,
getStdout
,
closed
,
createPipe
,
readProcessStdout
,
startProcess
,
stopProcess
)
pollScriptBlock
::
FilePath
->
Block
pollScriptBlock
path
=
runPollBlock
$
forever
$
yieldBlockUpdate
=<<
(
lift
blockScriptAction
)
pollScriptBlock
::
Interval
->
FilePath
->
Block
pollScriptBlock
interval
path
=
runPollBlock
'
interval
$
forever
$
yieldBlockUpdate
=<<
(
lift
blockScriptAction
)
where
blockScriptAction
::
BarIO
BlockOutput
blockScriptAction
=
do
...
...
This diff is collapsed.
Click to expand it.
src/QBar/Cli.hs
+
13
−
2
View file @
debd83a3
...
...
@@ -9,8 +9,10 @@ import QBar.Core
import
QBar.DefaultConfig
import
QBar.Server
import
QBar.Theme
import
QBar.Time
import
Control.Monad
(
join
)
import
Data.Maybe
(
fromMaybe
)
import
qualified
Data.Text.Lazy
as
T
import
Options.Applicative
...
...
@@ -92,6 +94,15 @@ blockParser =
scriptBlockParser
::
Parser
(
BarIO
()
)
scriptBlockParser
=
helper
<*>
do
poll
<-
switch
$
long
"poll"
<>
short
'p'
<>
help
"Run script in poll mode (every line of output updates the block)."
poll
<-
switch
$
long
"poll"
<>
short
'p'
<>
help
"Run script in poll mode (at regular intervals)"
-- HACK optparse-applicative does not support options of style --poll[=INTERVAL],
-- so we add a second option to specify the interval explicitly instead
-- https://github.com/pcapriotti/optparse-applicative/issues/243
pollInterval
<-
fromMaybe
defaultInterval
<$>
(
optional
$
IntervalSeconds
<$>
option
auto
(
long
"interval"
<>
short
'i'
<>
metavar
"SECONDS"
<>
(
help
$
"Interval to use for --poll mode (default: "
<>
humanReadableInterval
defaultInterval
<>
")"
)
))
script
<-
strArgument
(
metavar
"SCRIPT"
<>
help
"The script that will be executed with a shell."
)
return
$
(
if
poll
then
addBlock
.
pollScriptBlock
else
addBlock
.
scriptBlock
)
script
return
$
(
if
poll
then
addBlock
.
pollScriptBlock
pollInterval
else
addBlock
.
scriptBlock
)
script
This diff is collapsed.
Click to expand it.
src/QBar/Time.hs
+
4
−
1
View file @
debd83a3
{-# LANGUAGE OverloadedLists #-}
module
QBar.Time
(
SleepScheduler
,
HasSleepScheduler
(
..
),
Interval
,
createSleepScheduler
,
sleepUntil
,
sleepUntil'
,
sleepUntilInterval
,
sleepUntilInterval'
,
everyMinute
,
everyNSeconds
,
nextIntervalTime
)
where
module
QBar.Time
(
SleepScheduler
,
HasSleepScheduler
(
..
),
Interval
(
..
)
,
createSleepScheduler
,
sleepUntil
,
sleepUntil'
,
sleepUntilInterval
,
sleepUntilInterval'
,
everyMinute
,
everyNSeconds
,
nextIntervalTime
,
humanReadableInterval
)
where
import
Control.Concurrent.Async
import
Control.Concurrent.MVar
...
...
@@ -10,6 +10,7 @@ import Data.SortedList (SortedList, toSortedList, fromSortedList, singleton, par
import
Data.Ord
(
comparing
)
newtype
Interval
=
IntervalSeconds
Integer
deriving
(
Read
,
Show
)
-- |Describes an interval that is run every "n" seconds after midnight.
everyNSeconds
::
Integer
->
Interval
...
...
@@ -29,6 +30,8 @@ nextIntervalTime (IntervalSeconds intervalSeconds) = liftIO $ do
utctDayTime
=
fromInteger
$
(
intervalId
+
1
)
*
intervalSeconds
}
humanReadableInterval
::
Interval
->
String
humanReadableInterval
(
IntervalSeconds
i
)
=
show
i
<>
"s"
data
SleepScheduler
=
SleepScheduler
(
MVar
(
SortedList
ScheduledEvent
,
[
ScheduledEvent
]))
Event
.
Event
data
ScheduledEvent
=
ScheduledEvent
{
...
...
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