Skip to content

Commit 7edd774

Browse files
authored
Merge pull request #201 from tencentyun/feature_jojoliang_6a39e426
Feature jojoliang 6a39e426
2 parents 41d61ec + ffa9ed3 commit 7edd774

File tree

3 files changed

+73
-1
lines changed

3 files changed

+73
-1
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+
}

batch_test.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ func TestBatchService_DescribeJob(t *testing.T) {
194194
if !reflect.DeepEqual(ref, want) {
195195
t.Errorf("Batch.DescribeJob returned %+v, want %+v", ref, want)
196196
}
197-
198197
}
199198

200199
func TestBatchService_ListJobs(t *testing.T) {
@@ -387,3 +386,21 @@ func TestBatchService_UpdateJobsStatus(t *testing.T) {
387386
t.Errorf("Batch.UpdateJobsStatus returned %+v, want %+v", ref, want)
388387
}
389388
}
389+
390+
func TestBatchService_DeleteJob(t *testing.T) {
391+
setup()
392+
defer teardown()
393+
394+
mux.HandleFunc("/jobs/53dc6228-c50b-46f7-8ad7-65e7159f1aae", func(w http.ResponseWriter, r *http.Request) {
395+
testHeader(t, r, "x-cos-appid", "1250000000")
396+
testMethod(t, r, http.MethodDelete)
397+
})
398+
399+
headers := &BatchRequestHeaders{
400+
XCosAppid: 1250000000,
401+
}
402+
_, err := client.Batch.DeleteJob(context.Background(), "53dc6228-c50b-46f7-8ad7-65e7159f1aae", headers)
403+
if err != nil {
404+
t.Fatalf("Batch.DescribeJob returned error: %v", err)
405+
}
406+
}

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)