-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
38 lines (27 loc) · 1.09 KB
/
server.py
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
import sys
import time
from thrift.protocol import TBinaryProtocol
from thrift.transport import TTwisted
from twisted.internet import reactor
from twisted.python import log
from twisted.python.logfile import DailyLogFile
from txsnowflake import Config, SnowflakeServiceHandler
from txsnowflake.remote import SnowflakeService
__author__ = 'uzix'
def main():
if len(sys.argv) < 2:
print 'Usage: %s config_file' % sys.argv[0]
sys.exit()
log.startLogging(sys.stdout)
Config.init(sys.argv[1])
if Config.debug:
log.startLogging(sys.stdout)
else:
log.startLogging(DailyLogFile.fromFullPath(Config.get('log.file')))
handler = SnowflakeServiceHandler(Config.getint('worker.id'), Config.getint('datacenter.id'))
processor = SnowflakeService.Processor(handler)
server = TTwisted.ThriftServerFactory(processor=processor, iprot_factory=TBinaryProtocol.TBinaryProtocolFactory())
reactor.listenTCP(Config.getint('port', default=9999), server, interface=Config.get('listen', default="0.0.0.0"))
reactor.run()
if __name__ == '__main__':
main()