File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -14,9 +14,19 @@ def msg(conn, event):
1414
1515def updates (conn , event ):
1616 ts = event .get ('ts' , 0 )
17+ rows = list (r .db (CHAT ).table (MSGS ).filter (r .row [TS ] > ts ).run (conn ))
18+ if len (rows ) == 0 :
19+ wait (conn , ts )
20+ rows = list (r .db (CHAT ).table (MSGS ).filter (r .row [TS ] > ts ).run (conn ))
21+ assert (len (rows ) > 0 )
22+ rows .sort (key = lambda row : row [TS ])
23+ return rows
24+
25+ # TODO: have timeout
26+ def wait (conn , ts ):
1727 for row in (r .db (CHAT ).table (MSGS ).filter (r .row [TS ] > ts ).
1828 changes (include_initial = True ).run (conn )):
19- return row [ 'new_val' ]
29+ break
2030
2131def handler (conn , event ):
2232 fn = {'msg' : msg ,
Original file line number Diff line number Diff line change @@ -30,9 +30,15 @@ function updates(ts) {
3030 html_error = data . error . replace ( / \n / g, '<br/>' ) ;
3131 $ ( "#comments" ) . html ( "Error: <br/><br/>" + html_error + "<br/><br/>Consider refreshing." )
3232 } else {
33- //$("#comments").html(data.result.msg);
34- $ ( "#comments" ) . append ( data . result . msg + "<br/>" ) ;
35- updates ( data . result . ts ) ;
33+ var ts = 0 ;
34+ for ( var i = 0 , len = data . result . length ; i < len ; i ++ ) {
35+ row = data . result [ i ] ;
36+ $ ( "#comments" ) . append ( row . msg + "<br/>" ) ;
37+ if ( row . ts > ts ) {
38+ ts = row . ts ;
39+ }
40+ }
41+ updates ( ts ) ;
3642 }
3743 } ) ;
3844}
Original file line number Diff line number Diff line change @@ -59,9 +59,7 @@ def main():
5959 (balancer ['host_ip' ], balancer ['host_port' ], app_name ))
6060 wrjs (config_file , {'url' : url })
6161
62- #run additional scripts, if there are any
63- print '=' * 40
64-
62+ # run additional scripts, if there are any
6563 if "init.py" in app_files :
6664 print '=' * 40
6765 print "Running init.py"
You can’t perform that action at this time.
0 commit comments