Skip to content

Commit 6a05212

Browse files
author
jojoliang
committed
add delete batch job
1 parent c0c434b commit 6a05212

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

batch.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,3 +274,18 @@ func (s *BatchService) UpdateJobStatus(ctx context.Context, opt *BatchUpdateStat
274274
resp, err := s.client.send(ctx, &sendOpt)
275275
return &res, resp, err
276276
}
277+
278+
func (s *BatchService) DeleteJob(ctx context.Context, id string, headers *BatchRequestHeaders) (*Response, error) {
279+
if len(id) == 0 {
280+
return nil, fmt.Errorf("Id is invalid")
281+
}
282+
u := fmt.Sprintf("/jobs/%s", id)
283+
sendOpt := sendOptions{
284+
baseURL: s.client.BaseURL.BatchURL,
285+
uri: u,
286+
method: http.MethodDelete,
287+
optHeader: headers,
288+
}
289+
resp, err := s.client.send(ctx, &sendOpt)
290+
return resp, err
291+
}

example/batch/delete_job.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"net/http"
6+
"net/url"
7+
"os"
8+
9+
"github.com/tencentyun/cos-go-sdk-v5"
10+
"github.com/tencentyun/cos-go-sdk-v5/debug"
11+
)
12+
13+
func main() {
14+
uin := "100010805041"
15+
appid := 1259654469
16+
jobid := "49e0dd01-27a6-41a6-97b2-dda3cca19223"
17+
u, _ := url.Parse("https://" + uin + ".cos-control.ap-guangzhou.myqcloud.com")
18+
b := &cos.BaseURL{BatchURL: u}
19+
c := cos.NewClient(b, &http.Client{
20+
Transport: &cos.AuthorizationTransport{
21+
SecretID: os.Getenv("COS_SECRETID"),
22+
SecretKey: os.Getenv("COS_SECRETKEY"),
23+
Transport: &debug.DebugRequestTransport{
24+
RequestHeader: true,
25+
RequestBody: true,
26+
ResponseHeader: true,
27+
ResponseBody: true,
28+
},
29+
},
30+
})
31+
32+
headers := &cos.BatchRequestHeaders{
33+
XCosAppid: appid,
34+
}
35+
36+
_, err := c.Batch.DeleteJob(context.Background(), jobid, headers)
37+
if err != nil {
38+
panic(err)
39+
}
40+
}

0 commit comments

Comments
 (0)