Skip to content

Commit

Permalink
Added some verbose/debug logging and a session sample
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.macosforge.org/repository/ruby/ControlTower/trunk@4886 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information
jballanc committed Nov 5, 2010
1 parent c26c88a commit ca6b121
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/rack/session/gcd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def initialize(sid, store)
@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)
Expand Down Expand Up @@ -83,6 +84,7 @@ def generate_sid
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?
Expand Down
23 changes: 23 additions & 0 deletions sample/gcd_sessions.ru
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ca6b121

Please sign in to comment.