-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpool_worker.go
39 lines (35 loc) · 1.29 KB
/
pool_worker.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
package main
import (
"fmt"
"context"
"upload_dropbox_service"
)
func workerUploadFileToDropBox(id int, jobs <-chan UploadInfoAsyn) {
client := InitHttpClientKeepAlive()
for uploadInfoAsyn := range jobs {
fmt.Println("worker", id, "start upload")
responseInfo := uploadInfoAsyn.info.UploadFile(client)
fmt.Println("worker", id, "finished job")
uploadInfoAsyn.reponse <- responseInfo
close(uploadInfoAsyn.reponse)
}
}
func workerSendRequestToGRPC(id int, grpcServerAdress string, jobs <-chan UploadInfoAsyn) {
client := InitGRPCClient(grpcServerAdress)
for uploadInfoAsyn := range jobs {
fmt.Println("worker", id, "start send request to grpc server")
response, err := sendRequestToGPRC(client, uploadInfoAsyn.info)
fmt.Println("worker", id, "finished recevice response from grpc server")
uploadInfoAsyn.reponse <- ResponseInfo{response: response, err: err}
close(uploadInfoAsyn.reponse)
}
}
func sendRequestToGPRC(client upload_dropbox_service.DropboxServiceClient, info UploadInfo) (string, error) {
ctx, cancel := context.WithTimeout(context.Background(), timeOut)
defer cancel()
response, err := client.Upload(ctx, &upload_dropbox_service.UploadInfo{FullPath: info.fullPath, Data: info.data, Token: info.token})
if err != nil {
return "", err
}
return response.Message, nil
}