feat(miniooni): introduce the --repeat-every command line flag (#819)
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 https://github.com/ooni/probe/issues/2184
This commit is contained in:
parent
9a0153a349
commit
8aad36a257
|
@ -45,6 +45,7 @@ type Options struct {
|
||||||
ProbeServicesURL string
|
ProbeServicesURL string
|
||||||
Proxy string
|
Proxy string
|
||||||
Random bool
|
Random bool
|
||||||
|
RepeatEvery int64
|
||||||
ReportFile string
|
ReportFile string
|
||||||
TorArgs []string
|
TorArgs []string
|
||||||
TorBinary string
|
TorBinary string
|
||||||
|
@ -104,6 +105,10 @@ func init() {
|
||||||
getopt.FlagLong(
|
getopt.FlagLong(
|
||||||
&globalOptions.Random, "random", 0, "Randomize inputs",
|
&globalOptions.Random, "random", 0, "Randomize inputs",
|
||||||
)
|
)
|
||||||
|
getopt.FlagLong(
|
||||||
|
&globalOptions.RepeatEvery, "repeat-every", 0,
|
||||||
|
"Repeat the measurement every INTERVAL number of seconds", "INTERVAL",
|
||||||
|
)
|
||||||
getopt.FlagLong(
|
getopt.FlagLong(
|
||||||
&globalOptions.ReportFile, "reportfile", 'o',
|
&globalOptions.ReportFile, "reportfile", 'o',
|
||||||
"Set the report file path", "PATH",
|
"Set the report file path", "PATH",
|
||||||
|
@ -283,7 +288,20 @@ func MainWithConfiguration(experimentName string, currentOptions Options) {
|
||||||
currentOptions.ReportFile = "report.jsonl"
|
currentOptions.ReportFile = "report.jsonl"
|
||||||
}
|
}
|
||||||
log.Log = logger
|
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)
|
extraOptions := mustMakeMapAny(currentOptions.ExtraOptions)
|
||||||
annotations := mustMakeMapString(currentOptions.Annotations)
|
annotations := mustMakeMapString(currentOptions.Annotations)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user