From 69e3627f4210ed8b8aba2f1094d8c601fa93f60b Mon Sep 17 00:00:00 2001 From: jlapacik Date: Wed, 25 Jul 2018 07:22:21 -0700 Subject: [PATCH] controller sets Now time before enqueuing a query --- query/control/controller.go | 13 ++++++++++--- query/spec.go | 3 +++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/query/control/controller.go b/query/control/controller.go index 4c610b8a4c..969b86f1a8 100644 --- a/query/control/controller.go +++ b/query/control/controller.go @@ -81,12 +81,19 @@ func (c *Controller) QueryWithCompile(ctx context.Context, orgID platform.ID, qu return q, err } -// Query submits a query for execution returning immediately. -// The spec must not be modified while the query is still active. -// Done must be called on any returned Query objects. +// Query submits a query for execution returning immediately. Once a query +// is submitted, that is once a query is enqueued, the query spec must not +// be modified. Done must be called on any returned Query objects. func (c *Controller) Query(ctx context.Context, orgID platform.ID, qSpec *query.Spec) (query.Query, error) { q := c.createQuery(ctx, orgID) q.spec = *qSpec + + // Incoming query spec may have been produced by an entity other than the + // Flux interpreter, so we must set the default Now time if not already set. + if q.spec.Now.IsZero() { + q.spec.Now = q.now + } + err := c.enqueueQuery(q) return q, err } diff --git a/query/spec.go b/query/spec.go index a0b405ef7b..86aeadf9ff 100644 --- a/query/spec.go +++ b/query/spec.go @@ -45,6 +45,9 @@ func (q *Spec) Walk(f func(o *Operation) error) error { // Validate ensures the query is a valid DAG. func (q *Spec) Validate() error { + if q.Now.IsZero() { + return errors.New("now time must be set") + } return q.prepare() }