def on_finish(self): live_voting = rainwave.schedule.update_live_voting(self.sid) zeromq.publish({ "action": "live_voting", "sid": self.sid, "uuid_exclusion": None, "data": { "live_voting": live_voting }, }) super(SubmitVote, self).on_finish()
def _process_message(self, message, is_throttle_process=False): message_id = None if "message_id" in message: message_id = fieldtypes.zero_or_greater_integer(message['message_id']) throt_t = timestamp() - 3 self.msg_times = [ t for t in self.msg_times if t > throt_t ] if not is_throttle_process: self.msg_times.append(timestamp()) # log.debug("throttle", "%s - %s" % (len(self.msg_times), message['action'])) if self.throttled: # log.debug("throttle", "Currently throttled, adding to queue.") self.throttled_msgs.append(message) return elif len(self.msg_times) >= 5: # log.debug("throttle", "Too many messages, throttling.") self.throttled = True self.throttled_msgs.append(message) tornado.ioloop.IOLoop.instance().add_timeout(datetime.timedelta(seconds=0.5), self.process_throttle) return if message['action'] == "ping": self.write_message({ "pong": { "timestamp": timestamp() } }) return if message['action'] == "pong": self.write_message({ "pongConfirm": { "timestamp": timestamp() } }) return if message['action'] == "vote": zeromq.publish({ "action": "vote_by", "by": self.votes_by_key }) if message['action'] == "check_sched_current_id": self._do_sched_check(message) return message['action'] = "/api4/%s" % message['action'] if not message['action'] in api_endpoints: self.write_message({ "wserror": { "tl_key": "websocket_404", "text": self.locale.translate("websocket_404") } }) return endpoint = api_endpoints[message['action']](websocket=True) endpoint.locale = self.locale endpoint.request = FakeRequestObject(message, self.request.cookies) endpoint.sid = message['sid'] if ('sid' in message and message['sid']) else self.sid endpoint.user = self.user #pylint: disable=W0212 try: startclock = timestamp() # TODO: this should be a part of prepare_standalone! # it's required to see if another person on the same IP address has overriden the vote # for the in-memory user here, so it requires a DB fetch. if message['action'] == "/api4/vote" and self.user.is_anonymous(): self.user.refresh(self.sid) if "message_id" in message: if message_id == None: endpoint.prepare_standalone() raise APIException("invalid_argument", argument="message_id", reason=fieldtypes.zero_or_greater_integer_error, http_code=400) endpoint.prepare_standalone(message_id) else: endpoint.prepare_standalone() endpoint.post() endpoint.append("api_info", { "exectime": timestamp() - startclock, "time": round(timestamp()) }) if endpoint.sync_across_sessions: if endpoint.return_name in endpoint._output and isinstance(endpoint._output[endpoint.return_name], dict) and not endpoint._output[endpoint.return_name]['success']: pass else: zeromq.publish({ "action": "result_sync", "sid": self.sid, "user_id": self.user.id, "data": endpoint._output, "uuid_exclusion": self.uuid }) if message['action'] == "/api4/vote" and endpoint.return_name in endpoint._output and isinstance(endpoint._output[endpoint.return_name], dict) and endpoint._output[endpoint.return_name]['success']: live_voting = rainwave.schedule.update_live_voting(self.sid) endpoint.append("live_voting", live_voting) if self.should_vote_throttle(): zeromq.publish({ "action": "delayed_live_voting", "sid": self.sid, "uuid_exclusion": self.uuid, "data": { "live_voting": live_voting } }) else: zeromq.publish({ "action": "live_voting", "sid": self.sid, "uuid_exclusion": self.uuid, "data": { "live_voting": live_voting } }) except Exception as e: endpoint.write_error(500, exc_info=sys.exc_info(), no_finish=True) log.exception("websocket", "API Exception during operation.", e) finally: self.write_message(endpoint._output)
def sync_frontend_all(sid): zeromq.publish({"action": "update_all", "sid": sid})
def sync_frontend_ip(ip_address): zeromq.publish({"action": "update_ip", "ip": ip_address})
def sync_frontend_user_id(user_id): zeromq.publish({"action": "update_user", "user_id": user_id})
def sync_frontend_user_id(user_id): zeromq.publish({ "action": "update_user", "user_id": user_id })
def sync_frontend_ip(ip_address): zeromq.publish({ "action": "update_ip", "ip": ip_address })
def sync_frontend_all(sid): zeromq.publish({ "action": "update_all", "sid": sid })
def sync_frontend_key(key): zeromq.publish({"action": "update_listen_key", "listen_key": key})
def on_finish(self): live_voting = rainwave.schedule.update_live_voting(self.sid) zeromq.publish({ "action": "live_voting", "sid": self.sid, "uuid_exclusion": None, "data": { "live_voting": live_voting } }) super(SubmitVote, self).on_finish()