Perhaps the Scheduler can help.

On Saturday, July 5, 2014 11:47:39 AM UTC-5, Wonton wrote:
>
> Hello!
>
> As I commented in other post (
> https://groups.google.com/forum/#!topic/web2py/ZbEndj2H-fk) I have 
> problems using APNSWrapper feedback service sending push notifications.
>
> While I wait for an answer I've thought a possible solution to my problem. 
> This solution consists in:
> 1. I'm going to send push notifications to a series of device tokens.
> 2. For the current device token I mark it as "wrong" in the database.
> 3. I send the push notifications.
> 4.1. If the token is wrong the push notification is not sent and 
> APNSWrapper fails and the loop of tokens is broken.
> 4.2. If the token is right the push notification is sent.
> 5. I mark that token as "right" in the database.
>
> This way I can check the database and remove all tokens marked with 
> "wrong".
>
> The problem is that I'm executing this loop not in the main thread and I'm 
> having lots of problems: crashes, error for database connection closed, 
> etc...
>
> This is my code:
>
> ifcPushnotifications.py (is a module)
> push_thread = threading.Thread(target=__sendPushToUsersInBackground, args
> =(users, db))
> push_thread.start()
>
> def __sendPushToUsersInBackground(users, db):
>     wrapper = APNSNotificationWrapper('mycert.pem', False)
>     for user in users:
>         _tokenRow = db(db.push_notifs_table.userId == user['id'])
>         _tokenRow.update(status='wrong')
>         __sendPushToUser(user)
>         _tokenRow.update(status='right')
>
>
> If user's token is wrong __sendPushToUser fails and the loop leaves its 
> execution, so in the database it should be 'wrong'.
>
> My problem is that all 3 lines related to database (2 updates and the 
> query) fail randomly, sometimes crashes, sometimes returns an error of 
> closed database and do nothing, etc...
>
> So, how could I use my database inside a thread so I can avoid this errors?
>
> Thank you very much and kind regards!
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to