def consume(self, event): # type: (Mapping[str, Any]) -> None server_meta = event['server_meta'] environ = { 'REQUEST_METHOD': 'SOCKET', 'SCRIPT_NAME': '', 'PATH_INFO': '/json/messages', 'SERVER_NAME': '127.0.0.1', 'SERVER_PORT': 9993, 'SERVER_PROTOCOL': 'ZULIP_SOCKET/1.0', 'wsgi.version': (1, 0), 'wsgi.input': StringIO(), 'wsgi.errors': sys.stderr, 'wsgi.multithread': False, 'wsgi.multiprocess': True, 'wsgi.run_once': False, 'zulip.emulated_method': 'POST' } # We're mostly using a WSGIRequest for convenience environ.update(server_meta['request_environ']) request = WSGIRequest(environ) # Note: If we ever support non-POST methods, we'll need to change this. request._post = event['request'] request.csrf_processing_done = True user_profile = get_user_profile_by_id(server_meta['user_id']) request._cached_user = user_profile resp = self.handler.get_response(request) server_meta['time_request_finished'] = time.time() server_meta['worker_log_data'] = request._log_data resp_content = resp.content.decode('utf-8') result = { 'response': ujson.loads(resp_content), 'req_id': event['req_id'], 'server_meta': server_meta } redis_key = req_redis_key(event['req_id']) self.redis_client.hmset(redis_key, { 'status': 'complete', 'response': resp_content }) queue_json_publish(server_meta['return_queue'], result, lambda e: None)
def consume(self, event): # type: (Mapping[str, Any]) -> None server_meta = event['server_meta'] environ = {'REQUEST_METHOD': 'SOCKET', 'SCRIPT_NAME': '', 'PATH_INFO': '/json/messages', 'SERVER_NAME': '127.0.0.1', 'SERVER_PORT': 9993, 'SERVER_PROTOCOL': 'ZULIP_SOCKET/1.0', 'wsgi.version': (1, 0), 'wsgi.input': StringIO(), 'wsgi.errors': sys.stderr, 'wsgi.multithread': False, 'wsgi.multiprocess': True, 'wsgi.run_once': False, 'zulip.emulated_method': 'POST'} # We're mostly using a WSGIRequest for convenience environ.update(server_meta['request_environ']) request = WSGIRequest(environ) # Note: If we ever support non-POST methods, we'll need to change this. request._post = event['request'] request.csrf_processing_done = True user_profile = get_user_profile_by_id(server_meta['user_id']) request._cached_user = user_profile resp = self.handler.get_response(request) server_meta['time_request_finished'] = time.time() server_meta['worker_log_data'] = request._log_data resp_content = resp.content.decode('utf-8') result = {'response': ujson.loads(resp_content), 'req_id': event['req_id'], 'server_meta': server_meta} redis_key = req_redis_key(event['req_id']) self.redis_client.hmset(redis_key, {'status': 'complete', 'response': resp_content}) queue_json_publish(server_meta['return_queue'], result, lambda e: None)
def consume(self, event): server_meta = event["server_meta"] environ = { "REQUEST_METHOD": "SOCKET", "SCRIPT_NAME": "", "PATH_INFO": "/json/messages", "SERVER_NAME": "localhost", "SERVER_PORT": 9993, "SERVER_PROTOCOL": "ZULIP_SOCKET/1.0", "wsgi.version": (1, 0), "wsgi.input": StringIO(), "wsgi.errors": sys.stderr, "wsgi.multithread": False, "wsgi.multiprocess": True, "wsgi.run_once": False, "zulip.emulated_method": "POST", } # We're mostly using a WSGIRequest for convenience environ.update(server_meta["request_environ"]) request = WSGIRequest(environ) request._request = event["request"] request.csrf_processing_done = True user_profile = get_user_profile_by_id(server_meta["user_id"]) request._cached_user = user_profile resp = self.handler.get_response(request) server_meta["time_request_finished"] = time.time() server_meta["worker_log_data"] = request._log_data resp_content = resp.content result = {"response": ujson.loads(resp_content), "req_id": event["req_id"], "server_meta": server_meta} redis_key = req_redis_key(event["req_id"]) self.redis_client.hmset(redis_key, {"status": "complete", "response": resp_content}) queue_json_publish(server_meta["return_queue"], result, lambda e: None)