This repository has been archived by the owner on Feb 2, 2019. It is now read-only.
forked from kikinteractive/go-bqstreamer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
sync_options.go
68 lines (60 loc) · 1.95 KB
/
sync_options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Here be option functions for constructing a new Worker.
package bqstreamer
import (
"errors"
"time"
)
const (
// BigQuery has a quota policy regarding how big and often inserts should
// be. See the following article for more info:
//
// https://cloud.google.com/bigquery/quota-policy#streaminginserts
DefaultSyncMaxRetries = 3
DefaultSyncRetryInterval = 5 * time.Second
)
type SyncOptionFunc func(*SyncWorker) error
// SetSyncMaxRetries sets the maximum amount of retries a failed insert
// operation is allowed to retry,
// before dropping the rows and giving up on the insert operation entirely.
//
// NOTE value must be a non-negative int.
func SetSyncMaxRetries(retries int) SyncOptionFunc {
return func(w *SyncWorker) error {
if retries < 0 {
return errors.New("max retries value must be a non-negative int")
}
w.maxRetries = retries
return nil
}
}
// SetSyncRetryInterval sets the time delay before retrying a failed insert
// operation (if required).
//
// NOTE value must be a positive time.Duration.
func SetSyncRetryInterval(sleep time.Duration) SyncOptionFunc {
return func(w *SyncWorker) error {
if sleep <= 0 {
return errors.New("retry interval value must be a positive time.Duration")
}
w.retryInterval = sleep
return nil
}
}
// SetSyncIgnoreUnknownValues sets whether to accept rows that contain values
// that do not match the table schema. The unknown values are ignored.
// Default is false, which treats unknown values as errors.
func SetSyncIgnoreUnknownValues(ignore bool) SyncOptionFunc {
return func(w *SyncWorker) error {
w.ignoreUnknownValues = ignore
return nil
}
}
// SetSyncSkipInvalidRows sets whether to insert all valid rows of a request,
// even if invalid rows exist. The default value is false,
// which causes the entire request to fail if any invalid rows exist.
func SetSyncSkipInvalidRows(skip bool) SyncOptionFunc {
return func(w *SyncWorker) error {
w.skipInvalidRows = skip
return nil
}
}