Skip to content

Commit

Permalink
feat(miniooni): introduce the --repeat-every command line flag (#819)
Browse files Browse the repository at this point in the history
Until OONI Run v2 has support for repeating the measurement with a schedule, introduce a command line flag requested by users to repeat a measurement every given number of seconds.

Part of ooni/probe#2184
  • Loading branch information
bassosimone authored Jul 8, 2022
1 parent 9a0153a commit 8aad36a
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions internal/cmd/miniooni/libminiooni.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type Options struct {
ProbeServicesURL string
Proxy string
Random bool
RepeatEvery int64
ReportFile string
TorArgs []string
TorBinary string
Expand Down Expand Up @@ -104,6 +105,10 @@ func init() {
getopt.FlagLong(
&globalOptions.Random, "random", 0, "Randomize inputs",
)
getopt.FlagLong(
&globalOptions.RepeatEvery, "repeat-every", 0,
"Repeat the measurement every INTERVAL number of seconds", "INTERVAL",
)
getopt.FlagLong(
&globalOptions.ReportFile, "reportfile", 'o',
"Set the report file path", "PATH",
Expand Down Expand Up @@ -283,7 +288,20 @@ func MainWithConfiguration(experimentName string, currentOptions Options) {
currentOptions.ReportFile = "report.jsonl"
}
log.Log = logger
for {
mainSingleIteration(logger, experimentName, currentOptions)
if currentOptions.RepeatEvery <= 0 {
break
}
log.Infof("waiting %ds before repeating the measurement", currentOptions.RepeatEvery)
log.Info("use Ctrl-C to interrupt miniooni")
time.Sleep(time.Duration(currentOptions.RepeatEvery) * time.Second)
}
}

// mainSingleIteration runs a single iteration. There may be multiple iterations
// when the user specifies the --repeat-every command line flag.
func mainSingleIteration(logger model.Logger, experimentName string, currentOptions Options) {
extraOptions := mustMakeMapAny(currentOptions.ExtraOptions)
annotations := mustMakeMapString(currentOptions.Annotations)

Expand Down

0 comments on commit 8aad36a

Please sign in to comment.