python - Server Push Notification to Requested Client xyz: WebSocket Pusher/Pubnub -
lets consider have 1000 logged-in users in 1 of biz app. if 1 of user xyz
send request server server needs/taking 5-10 mins complete/returning request response.
note: app running on google app engine (python), raise deadline exceed error.
in case calling here task/background taskqueue. client doesn't comes know whether requested task status gets completed or not.
so status trying implement pushing feature (3rd party) using pubnub
or pusher
.
now concern here , how can publish message requested client xyz
only?
note: server publish status message should alert/notify requested client xyz
only, not logged-in users present in channel.
as newbie on over here pubnub
or pusher
.
so idea/logic cover kind of scenario.?
tech note: google app engine python, javascript.
update:
which plan of pubnub
(sandbox tier, etc..) need?
server-sent push notification on google app engine using taskqueues background processing long running tasks
this source code need in google app engine python solution notifying user when using google app engine task/background taskqueue has completed step in taskqueue processing steps , when taskqueue has been totally completed. wait! want send notification specific user initiated taskqueue request.
step 1 - how can publish message client xyz only?
this easy , here source code:
also secure app, make sure proper keys via: https://admin.pubnub.com dashboard.
javascript
<script src=https://pubnub.a.ssl.fastly.net/pubnub-3.4.3.min.js></script> <script>(function(){ var pubnub = pubnub.init({ subscribe_key : 'demo', ssl : true }); pubnub.subscribe({ channel : '0ihm4b2vpamzhawu0ethyawpvawdma3mg', // session id message : function(message) { alert(message) } // alert message }); })();</script>
note using simple javascript alert() function showing message, instead want turn more robust
<div>{message-here}</div>
notification area on page.
taskqueue setup
taskqueue.add( url='/my-long-task', countdown=1, method='get', params={ 'sessionid' : '0ihm4b2vpamzhawu0ethyawpvawdma3mg' } )
basically using user session id route communication user xyz. in google app engine python, publish using session id message state want client.
google app engine - python task
import webapp2 pubnub import pubnub ## download - https://raw.github.com/pubnub/pubnub-api/master/google-app-engine/python/pubnub.py pubnub = pubnub( "demo", "demo" ) def server_to_client_notify( sessionid, message ): pubnub.publish({ "channel" : sessionid, ## session id "message" : "hi!" }) class longrunningtaskqueue(webapp2.requesthandler): def get(self): ## session id sessionid = urllib.unquote(self.request.get( 'sessionid', '' )) server_to_client_notify( sessionid, "starting job" ) ## - lot of work - ## ## - lot of work - ## ## - lot of work - ## server_to_client_notify( sessionid, "your job complete" ) ## - lot of work - ## ## - lot of work - ## ## - lot of work - ## server_to_client_notify( sessionid, "your job has finished!" ) app = webapp2.wsgiapplication([('/my-long-task', longrunningtaskqueue)])
the basic concept post session id along taskqueue url command starts/adds task queue. when taskqueue starts, can grab url params.
in case wondering if there more 1 step, answer is: "there 1 step."
Comments
Post a Comment