Class: SessionCleanerTask
Instance Attribute Summary
#daemon_scheduler, #rufus_scheduler
Instance Method Summary
collapse
add_to, at, cron, environments, every, in, #log, should_run_in_current_environment?
Instance Method Details
#remove_old_sessions ⇒ Object
10
11
12
13
14
15
16
17
18
|
# File 'lib/scheduler_daemon/rails/generators/scheduler/templates/lib/scheduled_tasks/session_cleaner_task.rb', line 10
def remove_old_sessions
log "running the session cleaner"
if ActionController::Base.session_store == session_store_class
ActiveRecord::Base.connection.execute("DELETE FROM #{session_table_name} WHERE updated_at < '#{7.days.ago.to_s(:db)}'")
log "old sessions are gone!"
else
log "sessions are not stored in the database; nothing to do."
end
end
|
#run ⇒ Object
6
7
8
|
# File 'lib/scheduler_daemon/rails/generators/scheduler/templates/lib/scheduled_tasks/session_cleaner_task.rb', line 6
def run
remove_old_sessions
end
|
#session_store_class ⇒ Object
20
21
22
23
24
|
# File 'lib/scheduler_daemon/rails/generators/scheduler/templates/lib/scheduled_tasks/session_cleaner_task.rb', line 20
def session_store_class
return ActiveRecord::SessionStore if defined?(ActiveRecord::SessionStore)
return CGI::Session::ActiveRecordStore if defined?(CGI::Session::ActiveRecordStore)
end
|
#session_table_name ⇒ Object
26
27
28
|
# File 'lib/scheduler_daemon/rails/generators/scheduler/templates/lib/scheduled_tasks/session_cleaner_task.rb', line 26
def session_table_name
ActiveRecord::Base.pluralize_table_names ? :sessions : :session
end
|