コード例 #1
0
    def change_queue_core(self):
        app = api.get_global_app()

        index = 0
        with app.background_dbconn() as conn:
            conn.set_isolation_level(
                psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)

            curs = conn.cursor()
            # The channel string shall not be quoted in this context.
            curs.execute(f"LISTEN {self.channel};")

            while time.time() - self.last_check < 30:
                if select.select([conn], [], [], 5) == ([], [], []):
                    pass  # print(f"nothing; iterate {self.channel}")
                else:
                    # print(f"poll it {self.channel}")
                    conn.poll()
                    while conn.notifies:
                        notify = conn.notifies.pop(0)

                        index += 1
                        node = (time.time(), index, notify.payload)
                        self.thislist.append(node)
                        self.event.set()
                        self.event.clear()

                cutoff = time.time() - 60
                for cut, chrow in enumerate(self.thislist):
                    if chrow[0] > cutoff:
                        self.thislist = self.thislist[cut:]
                        break

        self.stop_change_queue(self.channel)
コード例 #2
0
def poll_listener(request, channel):
    key = request.query.get("key")
    index = request.query.get("index", None)

    index = 0 if index is None else int(index)
    listener = Listener.start_change_queue(key, channel)

    app = api.get_global_app()
    results = api.Results()
    with app.cancel_queue() as cancel:
        # return anything since
        results.tables["changes",
                       True] = listener.changes_since(cancel, index).as_tab2()
    return results.json_out()
コード例 #3
0
ファイル: application.py プロジェクト: jbmohler/yenot
import yenot.backend.api as api

app = api.get_global_app()


@app.get("/api/ping", name="ping", skip=["yenot-auth"])
def ping():
    return "."


@app.put("/api/request/cancel", name="api_request_cancel")
def api_request_cancel(request):
    token = request.query.get("token")
    app.cancel_request(token)
    return api.Results().json_out()