8
8
9
9
"github.com/AlecAivazis/survey/v2"
10
10
"github.com/MakeNowJust/heredoc"
11
+ "github.com/axiomhq/axiom-go/axiom/ingest"
11
12
"github.com/axiomhq/axiom-go/axiom/querylegacy"
12
13
"github.com/spf13/cobra"
13
14
@@ -17,8 +18,6 @@ import (
17
18
"github.com/axiomhq/cli/pkg/iofmt"
18
19
)
19
20
20
- const streamingDuration = time .Second * 2
21
-
22
21
type options struct {
23
22
* cmdutil.Factory
24
23
@@ -131,28 +130,32 @@ func run(ctx context.Context, opts *options) error {
131
130
fmt .Fprintf (opts .IO .Out (), "Streaming events from dataset %s:\n \n " , cs .Bold (opts .Dataset ))
132
131
}
133
132
134
- t := time . NewTicker ( streamingDuration )
135
- defer t . Stop ( )
136
-
137
- lastRequest := time . Now (). Add ( - time . Nanosecond )
133
+ var (
134
+ start = time . Now (). Add ( - time . Nanosecond )
135
+ cursor = ""
136
+ )
138
137
for {
139
- queryCtx , queryCancel := context .WithTimeout (ctx , streamingDuration )
140
-
141
- res , err := client .Datasets .QueryLegacy (queryCtx , opts .Dataset , querylegacy.Query {
142
- StartTime : lastRequest ,
138
+ res , err := client .Datasets .QueryLegacy (ctx , opts .Dataset , querylegacy.Query {
139
+ StartTime : start ,
143
140
EndTime : time .Now (),
141
+ Order : []querylegacy.Order {
142
+ {
143
+ Field : ingest .TimestampField ,
144
+ },
145
+ },
146
+ Cursor : cursor ,
144
147
}, querylegacy.Options {
145
- StreamingDuration : streamingDuration ,
148
+ StreamingDuration : time . Second * 5 ,
146
149
})
147
- if err != nil && ! errors .Is (err , context .DeadlineExceeded ) && ! errors .Is (err , context .Canceled ) {
148
- queryCancel ()
150
+ if err != nil {
151
+ if errors .Is (err , context .Canceled ) {
152
+ return nil
153
+ }
149
154
return err
150
155
}
151
156
152
- queryCancel ()
153
-
154
157
if res != nil && len (res .Matches ) > 0 {
155
- lastRequest = res .Matches [len (res .Matches )- 1 ].Time . Add ( time . Nanosecond )
158
+ cursor = res .Matches [len (res .Matches )- 1 ].RowID
156
159
157
160
for _ , entry := range res .Matches {
158
161
var data any
@@ -168,11 +171,5 @@ func run(ctx context.Context, opts *options) error {
168
171
}
169
172
}
170
173
}
171
-
172
- select {
173
- case <- ctx .Done ():
174
- return nil
175
- case <- t .C :
176
- }
177
174
}
178
175
}
0 commit comments