vaphes / pocketbase

PocketBase client SDK for python
https://pypi.org/project/pocketbase/
MIT License
359 stars 41 forks source link

Run background #34

Closed elsacutealways closed 1 year ago

elsacutealways commented 1 year ago

How to run subscribe() forever?

PFcs50 commented 1 year ago

I apologize if this isnt proper etiquite as I dont use gitbhub often but I am in dire need of help in regards to subscribe() and was wondering if you are able to share how you got it to work temporarily? I for the life of me can not figure out how to handle to callback argument requirement and there is very little discussion online about pocketbase in general nevermind this package.

m29h commented 1 year ago

A very naive example how subscribing is done is the following Note that this obviously assumes you have a collection with id = coll_id that has a record field called "title".

c = client.collection(coll_id)
def callback(e: MessageData):  ##this will be called completely out-of-order whenever an event happens in pocketbase
    print(e.record.title)   
c.subscribe(callback)
sleep(0.1)
for _ in range(10)
    c.create({"title": "Hello World"})   ## create a record (even an create in a completely different client will trigger above event)
    sleep(1)

I hope this helps. Note that unsusbscribe() currently has a bug #45 but the subscribe() method should work fine like above.

Mahfoudh94 commented 1 year ago

Hi, @elsacutealways. can you provide more details, I can't figure out what do you mean by "run subscribe forever", and if you happen to use or see the javascript/dart implementation of what you need, it would be of big help to send us in here.

m29h commented 1 year ago

Closed due to inactivity