Re: [Zope-dev] sessionDataManager should create it's temp/xxxx
OIC. Thanks! This patch probably makes sense for some class of usage. I'm a little skittish because I think doing magic (e.g. "if I dont find a data container where I said there was one, make one in /temp_folder") might tend to bite folks. Also, doing "writes on reads" (explicitly commiting a transaction in the middle of a request-bounded transaction) is probably a bad idea because it might cause half of something to be committed inadvertently. The "right" solution for this is to create some sort of analogue of "rc.d/init.d" for Zope where you can hook Zope startup and thus repopulate the temp_folder with the separate data containers then. I thought of this a while back but lacked the time to implement it. - C Darrell Gallion wrote:
I wanted each SessionDataManager to have it's own "Session Data Container" in the /temp_folder This allows me to invalidate them one by one and provide various timeouts.
Since these are not persistent, there's a problem. So I added properties to SessionDataManager so it could create it's own /temp_folder/SessionDataContainer if need be.
Maybe I'm using this all wrong?
Thanks --Darrell
__________________________________________________ Do You Yahoo!? Send FREE video emails in Yahoo! Mail! http://promo.yahoo.com/videomail/
Is it magic if the Session manager creates it's own data container? The first one is created for you but not by the Session system. That seems like magic. Since you say my approach to creating the tempData is flawed from a ZODB stand point. Then "rc.d/init.d" sound good. Although the /startup folder is a common idea for Windows users. Until the temp folder arrived I didn't need such a thing. Maybe the sessionDataManager could register a callback, called during startup. This might be a safer time to create any required temp data. --Darrell ===== Darrell Gallion __________________________________________________ Do You Yahoo!? Send FREE video emails in Yahoo! Mail! http://promo.yahoo.com/videomail/
Darrell Gallion wrote:
Is it magic if the Session manager creates it's own data container? The first one is created for you but not by the Session system. That seems like magic.
It's created by the Zope package, which indeed is magic, but something needed to populate it with default data; it has the minimum amount of magic necessary ;-)
Although the /startup folder is a common idea for Windows users. Until the temp folder arrived I didn't need such a thing.
Yup.
Maybe the sessionDataManager could register a callback, called during startup. This might be a safer time to create any required temp data.
The problem with this is that the SessionDataManager class can do this, but individual instances of the class cannot. There is no efficient way to find all the instances of one kind in a ZODB and call a method on them at start time unless you were to create some sort of custom registry someplace to do keep track of them. It seems cleaner to be procedural ala some sort of etc/rc.d/init.d at startup time which contains scripts that have the power to do arbitrary things to instances in the databse. Then the logic that does the necessary minimal magic in the Zope package now could be moved out and into this. This would be a great idea for a Product. - C
External methods aren't the best solution I know. It wasn't obvious to me how to call python scripts at this point. For that matter if this is a good point to do this kind of thing. Or how to hook the startup event with a product. Added these lines to the bottom of initialize(app) in application.py # Ensure that a startup folder exists if not hasattr(app, 'startup'): from OFS import Folder Folder.manage_addFolder(app, id='startup', title='Startup') get_transaction().note('Added startup folder') get_transaction().commit() # Call any external methods found in the startup folder # Only call external methods startup = getattr(app, 'startup') for obj in startup.objectIds(): obj=getattr(startup, obj) if hasattr(obj,'__call__') and obj.__class__.__name__=='ExternalMethod': obj(app) ===== Darrell Gallion __________________________________________________ Do You Yahoo!? Send FREE video emails in Yahoo! Mail! http://promo.yahoo.com/videomail/
That looks like a workable solution! This can also be done in a Product by getting hold of the supersecret attribute of the "context" object that is passed in to "initialize" which is the database connection (or maybe it's the root root object.. in either case, given either, you can get the other). It might be better that way in order to keep the logic out of the Zope init routine and in a separate product so it can be modified outside of Zope and used with various Zope versions until its baked enough to make it in... ----- Original Message ----- From: "Darrell Gallion" <dgallion1@yahoo.com> To: "Chris McDonough" <chrism@zope.com> Cc: <zope-dev@zope.org> Sent: Wednesday, January 09, 2002 7:13 PM Subject: Re: [Zope-dev] poor mans solution to startup folder
External methods aren't the best solution I know. It wasn't obvious to me how to call python scripts at this point. For that matter if this is a good point to do this kind of thing. Or how to hook the startup event with a product.
Added these lines to the bottom of initialize(app) in application.py
# Ensure that a startup folder exists if not hasattr(app, 'startup'): from OFS import Folder Folder.manage_addFolder(app, id='startup', title='Startup') get_transaction().note('Added startup folder') get_transaction().commit()
# Call any external methods found in the startup folder # Only call external methods startup = getattr(app, 'startup') for obj in startup.objectIds(): obj=getattr(startup, obj) if hasattr(obj,'__call__') and obj.__class__.__name__=='ExternalMethod': obj(app)
===== Darrell Gallion
__________________________________________________ Do You Yahoo!? Send FREE video emails in Yahoo! Mail! http://promo.yahoo.com/videomail/
Chris McDonough wrote:
OIC. Thanks!
This patch probably makes sense for some class of usage. I'm a little skittish because I think doing magic (e.g. "if I dont find a data container where I said there was one, make one in /temp_folder") might tend to bite folks. Also, doing "writes on reads" (explicitly commiting a transaction in the middle of a request-bounded transaction) is probably a bad idea because it might cause half of something to be committed inadvertently.
The "right" solution for this is to create some sort of analogue of "rc.d/init.d" for Zope where you can hook Zope startup and thus repopulate the temp_folder with the separate data containers then. I thought of this a while back but lacked the time to implement it.
- C
Actually, we did have the Temporary Folder have the capability to automatically import its contents at system startup, but that got tossed out as being function inappropriate to a temporary storage container by executive fiat.
Actually, we did have the Temporary Folder have the capability to automatically import its contents at system startup, but that got tossed out as being function inappropriate to a temporary storage container by executive fiat.
Yeah.. I actually think now that this was the right decision.
participants (3)
-
Chris McDonough -
Darrell Gallion -
Matthew T. Kromer