Skip to content
This repository was archived by the owner on Sep 28, 2021. It is now read-only.

Commit cbf57da

Browse files
Add reload limit (#416)
* Add possibility to limit reloads
1 parent fb94aae commit cbf57da

8 files changed

Lines changed: 39 additions & 10 deletions

File tree

‎cmd/build.go‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,15 @@ corectl build --connections ./myconnections.yml --script ./myscript.qvs`,
3939

4040
if !viper.GetBool("no-reload") {
4141
silent := viper.GetBool("silent")
42-
internal.Reload(ctx, state.Doc, state.Global, silent)
42+
limit := viper.GetInt("limit")
43+
internal.Reload(ctx, state.Doc, state.Global, silent, limit)
4344
}
4445

4546
if !viper.GetBool("no-save") {
4647
internal.Save(ctx, state.Doc)
4748
}
4849
},
49-
}, "script", "connections", "dimensions", "measures", "variables", "bookmarks", "objects", "no-reload", "silent", "no-save")
50+
}, "script", "connections", "dimensions", "measures", "variables", "bookmarks", "objects", "no-reload", "silent", "no-save", "limit")
5051

5152
var reloadCmd = withLocalFlags(&cobra.Command{
5253
Use: "reload",
@@ -61,11 +62,12 @@ var reloadCmd = withLocalFlags(&cobra.Command{
6162
Run: func(ccmd *cobra.Command, args []string) {
6263
state := internal.PrepareEngineState(rootCtx, headers, certificates, false, false)
6364
silent := viper.GetBool("silent")
65+
limit := viper.GetInt("limit")
6466

65-
internal.Reload(rootCtx, state.Doc, state.Global, silent)
67+
internal.Reload(rootCtx, state.Doc, state.Global, silent, limit)
6668

6769
if !viper.GetBool("no-save") {
6870
internal.Save(rootCtx, state.Doc)
6971
}
7072
},
71-
}, "silent", "no-save")
73+
}, "silent", "no-save", "limit")

‎cmd/flags.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ func initLocalFlags() {
8686
//bound to viper
8787
localFlags.Bool("no-save", false, "Do not save the app")
8888
localFlags.Bool("silent", false, "Do not log reload output")
89+
localFlags.Int("limit", 0, "Limit the number of rows to load")
8990
localFlags.Bool("no-reload", false, "Do not run the reload script")
9091
localFlags.Bool("suppress", false, "Suppress confirmation dialogue")
9192
localFlags.String("catwalk-url", "https://catwalk.core.qlik.com", "Url to an instance of catwalk, if not provided the qlik one will be used")

‎docs/corectl_build.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ corectl build --connections ./myconnections.yml --script ./myscript.qvs
2424
--connections string Path to a yml file containing the data connection definitions
2525
--dimensions string A list of generic dimension json paths
2626
-h, --help help for build
27+
--limit int Limit the number of rows to load
2728
--measures string A list of generic measures json paths
2829
--no-reload Do not run the reload script
2930
--no-save Do not save the app

‎docs/corectl_reload.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ corectl reload
1919
### Options
2020

2121
```
22-
-h, --help help for reload
23-
--no-save Do not save the app
24-
--silent Do not log reload output
22+
-h, --help help for reload
23+
--limit int Limit the number of rows to load
24+
--no-save Do not save the app
25+
--silent Do not log reload output
2526
```
2627

2728
### Options inherited from parent commands

‎docs/spec.json‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@
135135
"dimensions": {
136136
"description": "A list of generic dimension json paths"
137137
},
138+
"limit": {
139+
"description": "Limit the number of rows to load",
140+
"default": "0"
141+
},
138142
"measures": {
139143
"description": "A list of generic measures json paths"
140144
},
@@ -367,6 +371,10 @@
367371
"reload": {
368372
"description": "Reload and save the app",
369373
"flags": {
374+
"limit": {
375+
"description": "Limit the number of rows to load",
376+
"default": "0"
377+
},
370378
"no-save": {
371379
"description": "Do not save the app",
372380
"default": "false"

‎internal/reload.go‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
var transientLogged bool
1616

1717
// Reload reloads the app and prints the progress to system out.
18-
func Reload(ctx context.Context, doc *enigma.Doc, global *enigma.Global, silent bool) {
18+
func Reload(ctx context.Context, doc *enigma.Doc, global *enigma.Global, silent bool, limit int) {
1919

2020
var (
2121
reloadSuccessful bool
@@ -45,7 +45,13 @@ func Reload(ctx context.Context, doc *enigma.Doc, global *enigma.Global, silent
4545
}
4646
}
4747
}()
48-
reloadSuccessful, err = doc.DoReload(ctxWithReservedRequestID, 0, false, false)
48+
if limit == 0 {
49+
reloadSuccessful, err = doc.DoReload(ctxWithReservedRequestID, 0, false, false)
50+
} else {
51+
doc.SetFetchLimit(ctx, limit)
52+
reloadSuccessful, err = doc.DoReload(ctxWithReservedRequestID, 0, false, true)
53+
}
54+
4955
close(reloadDone)
5056
<-loggingDone
5157
} else {
@@ -69,10 +75,17 @@ func Reload(ctx context.Context, doc *enigma.Doc, global *enigma.Global, silent
6975
}
7076

7177
func logProgress(ctx context.Context, global *enigma.Global, reservedRequestID int, skipTransientLogs bool) {
78+
InteractDef := &enigma.InteractDef{}
79+
7280
progress, err := global.GetProgress(ctx, reservedRequestID)
7381
if err != nil {
7482
fmt.Println(err)
7583
} else {
84+
// While doing reload in debug mode (required for limit) engine will "pause" and InteractDone has to be sent to continue
85+
if progress.UserInteractionWanted {
86+
global.InteractDone(ctx, reservedRequestID, InteractDef)
87+
}
88+
7689
var text string
7790
if progress.TransientProgress != "" {
7891
if !skipTransientLogs {

‎test/corectl_integration_test.go‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ func TestBasicAnalyzing(t *testing.T) {
4040
func TestReload(t *testing.T) {
4141
p := toolkit.Params{T: t, Config: "test/projects/using-entities/corectl.yml", Engine: *toolkit.EngineStdIP, App: t.Name()}
4242
defer p.Reset()
43-
p.ExpectOK().Run("build")
43+
p.ExpectIncludes("<< 5 Lines fetched").Run("build")
44+
p.ExpectIncludes("<< 3 Lines fetched").Run("build", "--limit", "3")
45+
p.ExpectIncludes("<< 3 Lines fetched").Run("reload", "--limit", "3")
4446
p.ExpectGolden().Run("reload", "--silent")
4547
p.ExpectGolden().Run("reload", "--silent", "--no-save")
4648
}

‎test/golden/TestHelp_help_build.golden‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Flags:
1212
--connections string Path to a yml file containing the data connection definitions
1313
--dimensions string A list of generic dimension json paths
1414
-h, --help help for build
15+
--limit int Limit the number of rows to load
1516
--measures string A list of generic measures json paths
1617
--no-reload Do not run the reload script
1718
--no-save Do not save the app

0 commit comments

Comments
 (0)
⌂ 换网址