[macruby-changes] [4886] ControlTower/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Fri Nov 5 03:47:52 PDT 2010
Revision: 4886
http://trac.macosforge.org/projects/ruby/changeset/4886
Author: joshua.ballanco at apple.com
Date: 2010-11-05 03:47:48 -0700 (Fri, 05 Nov 2010)
Log Message:
-----------
Added some verbose/debug logging and a session sample
Modified Paths:
--------------
ControlTower/trunk/lib/rack/session/gcd.rb
Added Paths:
-----------
ControlTower/trunk/sample/gcd_sessions.ru
Modified: ControlTower/trunk/lib/rack/session/gcd.rb
===================================================================
--- ControlTower/trunk/lib/rack/session/gcd.rb 2010-11-05 10:10:04 UTC (rev 4885)
+++ ControlTower/trunk/lib/rack/session/gcd.rb 2010-11-05 10:47:48 UTC (rev 4886)
@@ -28,6 +28,7 @@
@session_timer.cancel! unless @session_timer.nil?
time_remaining = @session_expires_at - Time.now
if time_remaining < 0
+ warn "Session #{@session_id} has expired" if $DEBUG
@session_store.delete(@session_id)
else
@session_timer = Dispatch::Source.timer(time_remaining, 500, 0.5, @session_access_queue, &@timer_block)
@@ -83,6 +84,7 @@
end
def get_session(env, sid)
+ env['rack.errors'].puts("Searching through #{@sessions.length} live sessions") if $VERBOSE
session = @sessions[sid] if sid
unless sid and session
env['rack.errors'].puts("Session '#{sid.inspect}' not found, initializing...") if $VERBOSE and not sid.nil?
Added: ControlTower/trunk/sample/gcd_sessions.ru
===================================================================
--- ControlTower/trunk/sample/gcd_sessions.ru (rev 0)
+++ ControlTower/trunk/sample/gcd_sessions.ru 2010-11-05 10:47:48 UTC (rev 4886)
@@ -0,0 +1,23 @@
+require 'rack/session/gcd'
+
+class SessionCheck
+ def call(env)
+ session = env['rack.session']
+ if session
+ if session[:num_accesses]
+ session[:num_accesses] += 1
+ msg = "This session has been accessed #{session[:num_accesses]} times"
+ else
+ session[:num_accesses] = 1
+ msg = 'This is the first time this session has been accessed'
+ end
+ else
+ msg = 'Whoops! No session...'
+ end
+ [200, {'Content-Type' => 'text/plain'}, msg]
+ end
+end
+
+$VERBOSE = true, $DEBUG = true
+use Rack::Session::GCD, :expire_after => 30
+run SessionCheck.new
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101105/eb6a6421/attachment.html>
More information about the macruby-changes
mailing list