|
9 | 9 | class RedisPubsub(object): |
10 | 10 |
|
11 | 11 | def __init__(self, host='localhost', port=6379, *args, **kwargs): |
| 12 | + redis.connection.socket = gevent.socket # may not need this -- test |
12 | 13 | self.redis = redis.StrictRedis(host, port, *args, **kwargs) |
13 | 14 | self.pubsub = self.redis.pubsub(ignore_subscribe_messages=True) |
14 | 15 | self.subscriptions = {} |
@@ -38,8 +39,8 @@ def unsubscribe(self, sub_id): |
38 | 39 |
|
39 | 40 | def wait_and_get_message(self): |
40 | 41 | while True: |
41 | | - self.pubsub.get_message() # might need to monkey patch |
42 | | - gevent.sleep(.001) # may not need this sleep call |
| 42 | + self.pubsub.get_message() |
| 43 | + gevent.sleep(.001) # may not need this sleep call - test |
43 | 44 |
|
44 | 45 |
|
45 | 46 | class ValidationError(Exception): |
@@ -91,7 +92,7 @@ def subscribe(self, query, operation_name, callback, variables, context, |
91 | 92 |
|
92 | 93 | arg_definition = [arg_def for arg_def in |
93 | 94 | fields[subscription_name].args if |
94 | | - arg_def == arg.name.value][0] |
| 95 | + arg_def.name == arg.name.value][0] |
95 | 96 |
|
96 | 97 | args[arg_definition.name] = value_from_ast( |
97 | 98 | arg.value, |
@@ -131,49 +132,56 @@ def subscribe(self, query, operation_name, callback, variables, context, |
131 | 132 | ) |
132 | 133 |
|
133 | 134 | def on_message(root_value): |
134 | | - if isinstance(context, FunctionType): |
135 | | - context_promise = Promise( |
136 | | - lambda resolve: resolve(context()) |
137 | | - ) |
138 | | - else: |
139 | | - context_promise = Promise.resolve(context) |
140 | 135 |
|
141 | | - def context_promise_then(context): |
142 | | - if not filter_func(root_value, context): |
143 | | - return |
| 136 | + def context_promise_handler(): |
| 137 | + if isinstance(context, FunctionType): |
| 138 | + return context() |
| 139 | + else: |
| 140 | + return context |
| 141 | + |
| 142 | + def filter_func_promise_handler(context): |
| 143 | + return Promise.all([ |
| 144 | + context, |
| 145 | + filter_func(root_value, context) |
| 146 | + ]) |
144 | 147 |
|
| 148 | + def context_do_execute_handler(result): |
| 149 | + root_value, do_execute = result |
| 150 | + if not do_execute: |
| 151 | + return |
145 | 152 | execute( |
146 | 153 | self.schema, |
147 | 154 | parsed_query, |
148 | 155 | root_value, |
149 | 156 | context, |
150 | 157 | variables, |
151 | 158 | operation_name |
| 159 | + ).then( |
| 160 | + lambda data: callback(None, data) |
152 | 161 | ) |
153 | 162 |
|
154 | | - context_promise.then( |
155 | | - context_promise_then |
| 163 | + return Promise.resolve( |
| 164 | + ).then( |
| 165 | + context_promise_handler |
156 | 166 | ).then( |
157 | | - lambda data: callback(None, data) |
| 167 | + filter_func_promise_handler |
| 168 | + ).then( |
| 169 | + context_do_execute_handler |
158 | 170 | ).catch( |
159 | 171 | lambda error: callback(error) |
160 | 172 | ) |
161 | 173 |
|
162 | | - subs_promise = Promise( |
163 | | - lambda resolve: resolve(self.pubsub.subscribe( |
| 174 | + subscription_promises.append( |
| 175 | + self.pubsub.subscribe( |
164 | 176 | trigger_name, |
165 | 177 | on_message, |
166 | 178 | channel_options |
167 | | - )) |
168 | | - ) |
169 | | - |
170 | | - subs_promise.then( |
171 | | - lambda id: self.subscriptions[ |
172 | | - external_subscription_id].append(id) |
| 179 | + ).then( |
| 180 | + lambda id: self.subscriptions[ |
| 181 | + external_subscription_id].append(id) |
| 182 | + ) |
173 | 183 | ) |
174 | 184 |
|
175 | | - subscription_promises.append(subs_promise) |
176 | | - |
177 | 185 | return Promise.all(subscription_promises).then( |
178 | 186 | lambda result: external_subscription_id |
179 | 187 | ) |
|
0 commit comments