def magic_box(sproto, extra): sock = ZCONTEXT.socket(zmq.PUSH) sock.connect(ZSUBGATE) #gevent.sleep(0.001) # tcp min for 100% messages if sproto == "mode0_monitor": #print datetime.datetime.now(), "mon0" bus, bdata, updated = extra serialized = {"bdata_mode0": bdata} serialized["bdata_mode0"]['updated'] = updated serialized["bdata_mode0"]['bus_id'] = bus.id time_bst = REDIS.get("time_bst_%s" % bus.city_id) if time_bst: time_bst = pickle.loads(time_bst) serialized['time_bst'] = time_bst.get(bus.id, {}) sock.send("ru.bustime.bus_mode0__%s %s" % (bus.id, pickle_dumps(serialized))) #sock.send_pyobj(obj, flags=0, protocol=2) elif sproto == "mode1_monitor": bus, tosend = extra sock.send("ru.bustime.bus_mode1__%s %s" % (bus.id, tosend)) elif sproto == "modep_proto": bus, pdata = extra sock.send("ru.bustime.bus_mode0__%s %s" % (bus.id, pickle_dumps(pdata))) elif sproto == "amount_monitor": city, update = extra pi = pickle_dumps({"busamounts": update}) sock.send("ru.bustime.bus_amounts__%s %s" % (city.id, pi)) elif sproto == "stop_monitor": to_send = extra for nb, dataz in to_send: serialized = ajax_stop_id_f([nb], raw=True, data=dataz, single=True) pi = pickle_dumps(serialized) sock.send("ru.bustime.stop_id__%s %s" % (nb.id, pi)) sock.close() return True
def rpc_stop_ids(self, ids): ids = ujson.loads(ids) serialized = ajax_stop_id_f(ids, raw=True) return serialized