forked from msooner/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathG.py
More file actions
57 lines (46 loc) · 1.46 KB
/
G.py
File metadata and controls
57 lines (46 loc) · 1.46 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#-*-coding:utf-8-*-
from sqlalchemy.orm import scoped_session
from mapper.init import UnitymobSession
from conf import conf
from library.MyRedis import MyRedis
from library.MyRabbitmq import MyRabbitmq
from library.RPCClient import RPCClient
from library.Utils import Utils
from tornado.ioloop import IOLoop
class G(object):
_instance = None
@classmethod
def getInstance(cls):
if cls._instance is None:
cls._instance = cls()
return cls._instance
def __init__(self):
self.conf = conf
self.utils = Utils
self._session = None
@property
def currentIOloopInstance(self):
return IOLoop.current()
@property
def session(self):
if self._session is None:
self._session = scoped_session(UnitymobSession)
return self._session
@property
def redis(self):
return MyRedis.getInstance(host=conf.redis.host, port=conf.redis.port, password=conf.redis.password,
decode_responses=False)
@property
def rabbitmq(self):
""" 自定义rabbitmq """
return MyRabbitmq.getInstance(conf.rabbitmq.dsn)
@property
def rpc(self):
fb = conf.facebook
return RPCClient(fb.app_id, fb.app_secret, fb.rpc_endpoint)
def clear(self):
""" 释放资源 """
if self._session is not None:
self._session.remove()
self._session = None
del self.rabbitmq.channel