def gen(): q = Queue() log_subscriptions.append(q) try: while True: (event_id, result) = q.get() ev = ServerSentEvent(result, event_id) yield ev.encode() except GeneratorExit: # Or maybe use flask signals log_subscriptions.remove(q)
def gen(): q = Queue() subscriptions.append(q) try: while True: result = q.get() ev = ServerSentEvent(str(result)) yield ev.encode() except GeneratorExit: # Or maybe use flask signals subscriptions.remove(q)
def gen(): """Closure around a connected client""" queue = Queue() SUBSCRIPTIONS.append(queue) try: while True: result = queue.get() event = ServerSentEvent(str(result)) yield event.encode() except GeneratorExit: # Or maybe use flask signals SUBSCRIPTIONS.remove(queue)
def gen(session_id): q = subscriptions[session_id] q_size = len(q) log.info("pulling queue: %s" % q) runner = None suspend_user = True while not q.empty(): r = q.get() log.info("pulling from queue: %s" % r) if "action" in r.keys(): # do not suspend if we are only performing non-google apps actions if r["action"] in NO_SUSPEND_ACTIONS and q_size == 1: suspend_user = False # do not suspend the user if we are setting an ooo msg if r["action"] == "set_ooo_msg": suspend_user = False # do not suspend the user if we are resetting due to lost asset if r["action"] == "lost_asset": suspend_user = False # handle output for calendar events ownership if "change_events_ownership" in r.keys(): value = r["change_events_ownership"] if value: result = "<p>CHANGE EVENTS OWNERSHIP: %s</p>" % value else: result = "<p>CHANGE EVENTS OWNERSHIP: <span class='text-success'>SUCCESS</span></p>" elif r["action"] != "lost_asset": runner = r["runner"] result = runner.perform_action(r["connector"], r["action"], r["params"]) else: result = "<p>RESET SIGN-IN COOKIES: <span class='text-success'>SUCCESS</span></p>" log.info("result: %s" % result) ev = ServerSentEvent(str(result)) yield ev.encode() if runner is not None: suspend = runner.suspend_user(True) log.info("suspend: %s" % suspend) if not suspend_user: suspend = runner.suspend_user(False) log.info("un-suspend: %s" % suspend) del subscriptions[session_id] log.info("removing queue: %s" % q)
def error(): err = "" ev = ServerSentEvent(err) yield ev.encode()