@@ -19,6 +19,7 @@ type odpsClient struct {
19
19
20
20
logViewRetentionInDays int
21
21
isDryRun bool
22
+ retry func (f func () error ) error
22
23
}
23
24
24
25
// NewODPSClient creates a new odpsClient instance
@@ -27,6 +28,9 @@ func NewODPSClient(logger *slog.Logger, client *odps.Odps) *odpsClient {
27
28
logger : logger ,
28
29
client : client ,
29
30
logViewRetentionInDays : 2 ,
31
+ retry : func (f func () error ) error {
32
+ return retry (logger , 3 , 1000 , f )
33
+ },
30
34
}
31
35
}
32
36
@@ -49,7 +53,7 @@ func (c *odpsClient) ExecSQL(ctx context.Context, query string, additionalHints
49
53
// generate log view
50
54
url , err := c .generateLogView (taskIns )
51
55
if err != nil {
52
- err = e .Join (err , taskIns . Terminate ( ))
56
+ err = e .Join (err , c . terminate ( taskIns ))
53
57
return errors .WithStack (err )
54
58
}
55
59
c .logger .Info (fmt .Sprintf ("taskId: %s, log view: %s , hints: (%s)" , taskIns .Id (), url , getHintsString (hints )))
@@ -83,6 +87,13 @@ func (c *odpsClient) SetDefaultProject(project string) {
83
87
c .client .SetDefaultProjectName (project )
84
88
}
85
89
90
+ // SetRetry sets the retry configuration for the odps client
91
+ func (c * odpsClient ) SetRetry (max int , backoffMs int ) {
92
+ c .retry = func (f func () error ) error {
93
+ return retry (c .logger , max , int64 (backoffMs ), f )
94
+ }
95
+ }
96
+
86
97
// GetPartitionNames returns the partition names of the given table
87
98
// by querying the table schema.
88
99
func (c * odpsClient ) GetPartitionNames (_ context.Context , tableID string ) ([]string , error ) {
@@ -158,11 +169,6 @@ func (c *odpsClient) wait(taskIns *odps.Instance) <-chan error {
158
169
return errChan
159
170
}
160
171
161
- // retry retries the given function with exponential backoff
162
- func (c * odpsClient ) retry (f func () error ) error {
163
- return retry (c .logger , 3 , 1000 , f )
164
- }
165
-
166
172
func (c * odpsClient ) terminate (instance * odps.Instance ) error {
167
173
if instance == nil {
168
174
return nil
0 commit comments