4
4
from tornado .concurrent import run_on_executor
5
5
from concurrent .futures import ThreadPoolExecutor
6
6
from swift_rpc .mq import rq_conn ,redis_conn
7
- from config import *
8
7
9
8
class _Handler (web .RequestHandler ):
10
9
__ALLOWEDUA__ = ('swift_rpc' )
@@ -16,25 +15,25 @@ def initialize(self):
16
15
17
16
@gen .coroutine
18
17
def prepare (self ):
19
- if SAFE_UA_MODE :
18
+ if self . config . SAFE_UA_MODE :
20
19
ua = self .request .headers .get ('User-Agent' )
21
20
#if ua not in self.__ALLOWEDUA__:
22
- if ua not in UA_ALLOW :
21
+ if ua not in self . config . UA_ALLOW :
23
22
self .log .info ('Received request from UA {0}' .format (ua ))
24
23
self .write ({'error' : 'User agent not allowed: {0}' .format (ua )})
25
24
self .finish ()
26
25
27
- if SAFE_TOKEN_MODE :
26
+ if self . config . SAFE_TOKEN_MODE :
28
27
token = self .request .headers .get ('Token' )
29
- if token not in TOKEN_ALLOW :
28
+ if token not in self . TOKEN_ALLOW :
30
29
self .log .info ('Received request from Token {0}' .format (token ))
31
30
self .write ({'error' : 'Token not allowed: {0}' .format (token )})
32
31
self .finish ()
33
32
34
- if REMOTE_IP_MODE :
33
+ if self . config . REMOTE_IP_MODE :
35
34
remote_ip = self .request .headers .get ("X-Real-IP" )
36
35
remote_ip = remote_ip if remote_ip else self .request .remote_ip
37
- if remote_ip not in REMOTE_ALLOW :
36
+ if remote_ip not in self . config . REMOTE_ALLOW :
38
37
self .log .info ('Received request from REMOTE IP {0}' .format (remote_ip ))
39
38
self .write ({'error' : 'IP not allowed: {0}' .format (remote_ip )})
40
39
self .finish ()
@@ -103,17 +102,14 @@ class _MessageQueueBase(_Handler):
103
102
@gen .coroutine
104
103
def get (self ):
105
104
args , kwargs = yield self .args_kwargs ()
106
- print args ,kwargs
107
105
try :
108
106
job = rq_conn .enqueue ('api.' + self .func [0 ].func_name ,* args ,** kwargs )
109
107
"""
110
108
will fix better
111
- #result = q.enqueue("test_server."+self.func[0].func_name, *args,**kwargs)
112
109
# r.lpush('task',msgpack.packb([self.func[0].func_name,args,kwargs]))
113
110
"""
114
111
self .write ({'response' : 'commit' ,'job' :job .key })
115
112
except Exception as e :
116
- print str (e )
117
113
self .write ({'error' : str (e )})
118
114
119
115
if __name__ == "__main__" :
0 commit comments