From 9bd50417af818bd0d55cc1b29c4edb35cfcd95ac Mon Sep 17 00:00:00 2001 From: Klesh Wong Date: Thu, 21 Apr 2022 21:49:18 +0800 Subject: [PATCH 1/2] feat: press c to cancel execution for directrun --- runner/directrun.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/runner/directrun.go b/runner/directrun.go index 4c2fa1594b4..fecf449f575 100644 --- a/runner/directrun.go +++ b/runner/directrun.go @@ -2,6 +2,8 @@ package runner import ( "context" + "os" + "os/exec" "github.com/merico-dev/lake/config" "github.com/merico-dev/lake/logger" @@ -39,11 +41,27 @@ func DirectRun(cmd *cobra.Command, args []string, pluginTask core.PluginTask, op if err != nil { panic(err) } + + exec.Command("stty", "-F", "/dev/tty", "cbreak", "min", "1").Run() + ctx, cancel := context.WithCancel(context.Background()) + go func() { + buf := make([]byte, 1) + n, err := os.Stdin.Read(buf) + if err != nil { + panic(err) + } else if n == 1 && buf[0] == 99 { + cancel() + } else { + println("unknown key press, code: ", buf[0]) + } + }() + println("press `c` to send cancel signal") + err = RunPluginSubTasks( cfg, log, db, - context.Background(), + ctx, cmd.Use, options, pluginTask, From 490c31a383e9d684df02553570fd54c7dc1f0391 Mon Sep 17 00:00:00 2001 From: Klesh Wong Date: Thu, 21 Apr 2022 21:49:53 +0800 Subject: [PATCH 2/2] fix: task hangs indefinitely if more than one error occurs within `Input` logic --- plugins/helper/api_collector.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/helper/api_collector.go b/plugins/helper/api_collector.go index 5fecac5c256..069a5abd49e 100644 --- a/plugins/helper/api_collector.go +++ b/plugins/helper/api_collector.go @@ -179,7 +179,9 @@ func (collector *ApiCollector) Execute() error { break } } - wg.Wait() + if err == nil { + wg.Wait() + } } else { // or we just did it once err = collector.exec(nil)