Giter VIP home page Giter VIP logo

asyncpg-listen's People

Contributors

dependabot[bot] avatar pliner avatar spaceorc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

asyncpg-listen's Issues

Connection pool

Many thanks for sharing and maintaining this valuable project. Is there a way to use the connect_func with a connection from a connection pool?

pgpool = await asyncpg.create_pool(dsn=myl_dsn)
async with pgpool.acquire() as connection: 

How do I pass additional args to the callback func

I am trying to implement this in a FastAPI/Websockets app, so that when a table update has been made, the changes (or a simple message) is pushed back to the listening client. Each client could potentially be listening to different channels, in this example they are all listening to "customer2" .

What I need is to pass the websocket argument to the notification handler, so that instead of just printing it, it sends back the payload to whichever client was listening. This is where I am a bit stuck, as my knowledge of asyncio is limited. Any help most appreciated.

`
@app.websocket("/ws")
async def websocket_endpoint(websocket: WebSocket):
await websocket.accept()

try:
    listener = asyncpg_listen.NotificationListener(asyncpg_listen.connect_func(dsn))
    listener_task = asyncio.create_task(
      listener.run(
        {"customer2": handle_notifications},
        policy=asyncpg_listen.ListenPolicy.LAST,
        notification_timeout=50
        )
    )
    # add it to the list so they can be closed if the server is shutdown
    all_listener_tasks.append(listener_task)

except WebSocketDisconnect:
    logger.info('Client has disconnected') # maybe more needs to be done to clean up ....
    return

async def handle_notifications(notification: asyncpg_listen.NotificationOrTimeout) -> None:
print(f"{notification} has been received, sent to websocket ?")
`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.