Skip to content

Commit

Permalink
fix: expose connect timeout value
Browse files Browse the repository at this point in the history
  • Loading branch information
wyattjoh committed Jan 21, 2021
1 parent e52ab0d commit 4a5d08d
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func run(c *cli.Context) error {
databaseURI := c.String("mongoDBURI")
dryRun := c.Bool("dryRun")
disableWatcher := c.Bool("disableWatcher")
mongoDBConnectTimeout := c.Duration("mongoDBConnectTimeout")

// Set the batch size.
counts.MaxBatchWriteSize = c.Int("batchSize")
Expand All @@ -38,7 +39,7 @@ func run(c *cli.Context) error {
databaseName := u.Path[1:]

// Create a context for connecting to MongoDB.
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), mongoDBConnectTimeout)
defer cancel()

// Connect to MongoDB now.
Expand All @@ -56,7 +57,7 @@ func run(c *cli.Context) error {
}()

// Ensure we're connected to the primary.
ctx, cancel = context.WithTimeout(context.Background(), 2*time.Second)
ctx, cancel = context.WithTimeout(context.Background(), mongoDBConnectTimeout)
defer cancel()

if err := client.Ping(ctx, readpref.Primary()); err != nil {
Expand Down Expand Up @@ -188,6 +189,12 @@ func main() {
Value: 1000,
EnvVars: []string{"BATCH_SIZE"},
},
&cli.DurationFlag{
Name: "mongoDBConnectTimeout",
Usage: "used to specify the timeout for connecting to MongoDB",
Value: 1 * time.Minute,
EnvVars: []string{"MONGODB_CONNECT_TIMEOUT"},
},
}
app.Action = run

Expand Down

0 comments on commit 4a5d08d

Please sign in to comment.