Hi~
Hi Ezra,
Ezra Zygmuntowicz wrote:
Backgroundrb is not a session container
so it won't work like you want.
I don't understand what you mean by 'not a session container,' It's listed
as an alternative to PStore and ActiveRecord session stores. I really don't
know much of anything about session management mechanisms and I have a
feeling you're telling me something I need to understand. Could you say
more about this please?
I think there is some confusion n the wiki. There is a DRb session container that you can use that comes with rails. BackgrounDRb is a rails plugin that I wrote for running long background tasks with hook for ajax progress bars or status updates in the browser. BackgrounDRb has nothing to do with sessions and will not work as a session container. For session containers here are your main options:
Pstore: filesystm storage, slowest of all the session containers.
ActiveRecord session store: stores sessions in a database table. Fast
DRb session store: similar speed to ActiveRecord store but not as robust and has less features. I have never used this one for production and i dont think that many people use this one.
Memcached: fastest session container but requires running extra daemons. Use this if you need to scale to the moon.
Stefan Kaeys Mysql session store: Faster then AR session store because its direct sql access. worth lookin at.
Out of all these the one I usualy use most is ActiveRecord store. Its very easy to set up and is pretty fast. This is the one I recommend. You can always change it later if it becomes necessary but it will handle all but the hugest sites fast.
The best way to do what you want would be
to use the ActiveRecord session store to store
your sessions in the db. Then make a cron job
that wakes up ever 10 minutes or so and deletes
the session and objects that folks abandoned.
The documentation on the wiki (I think) says that cron jobs are very high
cost compared to Backgroundrb and gives the impression that Backgroundrb is
a lightweight alternative that combines the session store mechanism with
cron-like worker processes. I misunderstood?
Backgroundrb does have cron like workers. And you can manage them from your rails app. But it is not a session container. So I think it can work for what you want to do.
The main issue I'm trying to get my arms around is how to get at the data
the user entered during their session so it can be deleted. Is it possible
for the cron job to access the application data? Do you know of any online
examples of how that would be done? The following happens when the user
explicitly logs out of the app.
Are you marking your records with some kind of identifier so you can delete everything someone created? Or how will you know which objects to delete when you clean up after them?
def cleanup
emrec = find_emrec # get the parent record; its id is stored in a
session variable
files = Tempfilerec.find(:all, :conditions => ["emrec_id = ?",
emrec.id]) # get the names of all the files the visitor has created
files.each {|file| FileUtils.rm "public/#{file.filename}" } # delete
the files
emrec.destroy # delete all the db records the visitor has created
reset_session
end
I need to do the same processing when the user abandons a session. Can I do
this from a script run as a cron job?
Thanks very much for any help understanding how to go about this.
Best regards,
Bill
If you store your sessions in the ActiveRecord session container you can query it like any other db table. So you can do a query for all the sessions that have no activity for 15 minutes or however long you want. Then use that info to delete the correct records.
BackgrounDRb can be used to do what you want. But you may want to keep it simple and use script/runner and cron.
-Ezra