source: subversion/sites/rails_port/lib/daemons/session_cleanup.rb @ 3206

Last change on this file since 3206 was 3206, checked in by tomhughes, 13 years ago

Make as executable.

  • Property svn:executable set to *
File size: 1.1 KB
Line 
1#!/usr/bin/env ruby
2
3#You might want to change this
4#ENV["RAILS_ENV"] ||= "development"
5
6require File.dirname(__FILE__) + "/../../config/environment"
7
8require 'pstore'
9
10terminated = false
11
12session_path = ActionController::Base.session_options[:tmpdir]
13
14def expire_session(name)
15  ActiveRecord::Base.logger.info("Expiring session #{File.basename(name)}")
16  FileUtils.rm_f(name)
17end
18
19while (true) do
20  Dir.foreach(session_path) do |session_name|
21    if session_name =~ /^ruby_sess\./
22      session_name = session_path + "/" + session_name
23      session = PStore.new(session_name)
24
25      session.transaction do |session|
26        session_hash = session['hash']
27
28        if session_hash
29          session_stat = File::Stat.new(session_name)
30            puts session_hash[:token]
31
32          if session_hash[:token] and User.find_by_token(session_hash[:token])
33#            expire_session(session_name) if session_stat.mtime < 1.day.ago
34          else
35            expire_session(session_name) if session_stat.mtime < 1.hour.ago
36          end
37        else
38          expire_session(session_name)
39        end
40      end
41    end
42  end
43
44  sleep 15.minutes
45end
Note: See TracBrowser for help on using the repository browser.