aboutsummaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
Diffstat (limited to 'commands')
-rw-r--r--commands/bridge_pull.go53
-rw-r--r--commands/bridge_push.go50
2 files changed, 96 insertions, 7 deletions
diff --git a/commands/bridge_pull.go b/commands/bridge_pull.go
index 2edabfaf..0f3b8413 100644
--- a/commands/bridge_pull.go
+++ b/commands/bridge_pull.go
@@ -1,6 +1,10 @@
package commands
import (
+ "context"
+ "fmt"
+ "os"
+ "sync"
"time"
"github.com/spf13/cobra"
@@ -31,12 +35,59 @@ func runBridgePull(cmd *cobra.Command, args []string) error {
return err
}
+ parentCtx := context.Background()
+ ctx, cancel := context.WithCancel(parentCtx)
+ defer cancel()
+
+ // buffered channel to avoid send block at the end
+ done := make(chan struct{}, 1)
+
+ var mu sync.Mutex
+ interruptCount := 0
+ interrupt.RegisterCleaner(func() error {
+ mu.Lock()
+ if interruptCount > 0 {
+ fmt.Println("Received another interrupt before graceful stop, terminating...")
+ os.Exit(0)
+ }
+
+ interruptCount++
+ mu.Unlock()
+
+ fmt.Println("Received interrupt signal, stopping the import...\n(Hit ctrl-c again to kill the process.)")
+
+ // send signal to stop the importer
+ cancel()
+
+ // block until importer gracefully shutdown
+ <-done
+ return nil
+ })
+
// TODO: by default import only new events
- err = b.ImportAll(time.Time{})
+ events, err := b.ImportAll(ctx, time.Time{})
if err != nil {
return err
}
+ importedIssues := 0
+ importedIdentities := 0
+ for result := range events {
+ fmt.Println(result.String())
+
+ switch result.Event {
+ case core.ImportEventBug:
+ importedIssues++
+ case core.ImportEventIdentity:
+ importedIdentities++
+ }
+ }
+
+ // send done signal
+ close(done)
+
+ fmt.Printf("Successfully imported %d issues and %d identities with %s bridge\n", importedIssues, importedIdentities, b.Name)
+
return nil
}
diff --git a/commands/bridge_push.go b/commands/bridge_push.go
index 11f5ca82..77fe8b29 100644
--- a/commands/bridge_push.go
+++ b/commands/bridge_push.go
@@ -1,7 +1,10 @@
package commands
import (
+ "context"
"fmt"
+ "os"
+ "sync"
"time"
"github.com/spf13/cobra"
@@ -32,20 +35,55 @@ func runBridgePush(cmd *cobra.Command, args []string) error {
return err
}
+ parentCtx := context.Background()
+ ctx, cancel := context.WithCancel(parentCtx)
+ defer cancel()
+
+ done := make(chan struct{}, 1)
+
+ var mu sync.Mutex
+ interruptCount := 0
+ interrupt.RegisterCleaner(func() error {
+ mu.Lock()
+ if interruptCount > 0 {
+ fmt.Println("Received another interrupt before graceful stop, terminating...")
+ os.Exit(0)
+ }
+
+ interruptCount++
+ mu.Unlock()
+
+ fmt.Println("Received interrupt signal, stopping the import...\n(Hit ctrl-c again to kill the process.)")
+
+ // send signal to stop the importer
+ cancel()
+
+ // block until importer gracefully shutdown
+ <-done
+ return nil
+ })
+
// TODO: by default export only new events
- out, err := b.ExportAll(time.Time{})
+ events, err := b.ExportAll(ctx, time.Time{})
if err != nil {
return err
}
- for result := range out {
- if result.Err != nil {
- fmt.Println(result.Err, result.Reason)
- } else {
- fmt.Printf("%s: %s\n", result.String(), result.ID)
+ exportedIssues := 0
+ for result := range events {
+ fmt.Println(result.String())
+
+ switch result.Event {
+ case core.ExportEventBug:
+ exportedIssues++
}
}
+ // send done signal
+ close(done)
+
+ fmt.Printf("Successfully exported %d issues with %s bridge\n", exportedIssues, b.Name)
+
return nil
}