service.py 818 Bytes
Newer Older
Wei Shoulin's avatar
Wei Shoulin committed
1
import os
Shoulin Wei's avatar
init  
Shoulin Wei committed
2
import grpc
Wei Shoulin's avatar
ephem    
Wei Shoulin committed
3
from csst_dfs_commons.models.errors import CSSTFatalException
Shoulin Wei's avatar
init  
Shoulin Wei committed
4
class ServiceProxy:
Wei Shoulin's avatar
Wei Shoulin committed
5
6
    def __init__(self):
        self.gateway = os.getenv("CSST_DFS_GATEWAY",'172.31.248.218:30880')
Shoulin Wei's avatar
init  
Shoulin Wei committed
7

Wei Shoulin's avatar
ephem    
Wei Shoulin committed
8
    def channel(self):
Wei Shoulin's avatar
Wei Shoulin committed
9
10
        options = (('grpc.max_send_message_length', 1000 * 1024 * 1024),
                    ('grpc.max_receive_message_length', 1000 * 1024 * 1024))     
Wei Shoulin's avatar
Wei Shoulin committed
11
12
        # channel = grpc.insecure_channel(self.gateway, options = options, compression = grpc.Compression.Gzip)
        channel = grpc.insecure_channel(self.gateway, options = options)
Wei Shoulin's avatar
ephem    
Wei Shoulin committed
13
14
15
16
17
18
        try:
            grpc.channel_ready_future(channel).result(timeout=10)
        except grpc.FutureTimeoutError:
            raise CSSTFatalException('Error connecting to server {}'.format(self.gateway))
        else:
            return channel