Skip to content

Commit

Permalink
Update starttime for querybroker script runner
Browse files Browse the repository at this point in the history
Summary: There was a bug here, since the ticker doesn't do an initial tick when initialized. So, if a user wanted to run a script every 10s, the first tick would actually use a starttime equivalent to '-20s' rather than '-10s'

Test Plan: Skaffold deploy Vizier

Reviewers: philkuz, vihang

Reviewed By: philkuz

Signed-off-by: Michelle Nguyen <michellenguyen@pixielabs.ai>

Differential Revision: https://phab.corp.pixielabs.ai/D11276

GitOrigin-RevId: 0b5e512
  • Loading branch information
aimichelle authored and copybaranaut committed Apr 21, 2022
1 parent b52ac57 commit 3beb62a
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ func (r *runner) start() {
return
}
ticker := time.NewTicker(time.Duration(r.cronScript.FrequencyS) * time.Second)
r.lastRun = time.Now().Add(time.Second * time.Duration(-1*r.cronScript.FrequencyS))
r.lastRun = time.Now()

go func() {
defer ticker.Stop()
Expand All @@ -465,16 +465,17 @@ func (r *runner) start() {
}

// TODO(michelle): We may want to monitor the stream to ensure the script runs successfully.
startTime := r.lastRun
r.lastRun = time.Now()
_, err := r.vzClient.ExecuteScript(ctx, &vizierpb.ExecuteScriptRequest{
QueryStr: r.cronScript.Script,
Configs: &vizierpb.Configs{
OTelEndpointConfig: otelEndpoint,
PluginConfig: &vizierpb.Configs_PluginConfig{
StartTimeNs: r.lastRun.UnixNano(),
StartTimeNs: startTime.UnixNano(),
},
},
})
r.lastRun = r.lastRun.Add(time.Second * time.Duration(r.cronScript.FrequencyS))
if err != nil {
log.WithError(err).Error("Failed to execute cronscript")
}
Expand Down

0 comments on commit 3beb62a

Please sign in to comment.