bot403 has asked for the wisdom of the Perl Monks concerning the following question:
I have an object which wraps some DB interaction with a destructor that sets a particular database column if the object's destructor was called while the object was in an "unclean" state. This is especially useful to know if I received a SIGTERM or somesuch while I was trying to manipulate the object. Specifically I update a status indicator from "Working" to "Aborted"
I'm having trouble getting the desctructor to work properly. Sometimes the database handle gets destroyed before my object's destructor is called and I get a cascade of errors.
Is there any good method to keep the database open somehow until all of my object's destructors are called? The database reference is currently a package scoped my variable. I tried putting a reference to it in every object instance, but it still went away at inconvenient times.
I suppose I could maintain a list of objects and walk the list calling destructors (or a cleanup method) when I receive a TERM signal. That seems unclean and probably wrong. It also won't catch error cases when my object was destroyed (i.e. went out of scope) in other cases due to programming errors.
Is there any way to accomplish this or am I asking too much of the perl interpreter at shutdown time?
Edit:Yea, the design does fail hard for now. I'm working towards redesiging the application. The reason I havent used transactions is that this perl process communicates the status of the object to the frontend website via the status column. Therefore I need to commit so the website sees the new data and the working state. If the perl process aborts I'd like to set the status to 'Aborted' or 'Failed'. Now it just stays in the 'Working' state.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Object Destructors and Signals
by ikegami (Patriarch) on Nov 04, 2010 at 23:03 UTC | |
by tye (Sage) on Nov 05, 2010 at 04:41 UTC | |
by ikegami (Patriarch) on Nov 05, 2010 at 16:22 UTC | |
|
Re: Object Destructors and Signals
by aquarium (Curate) on Nov 04, 2010 at 23:59 UTC | |
|
Re: Object Destructors and Signals
by locked_user sundialsvc4 (Abbot) on Nov 05, 2010 at 01:53 UTC | |
|
Re: Object Destructors and Signals
by jeffa (Bishop) on Nov 04, 2010 at 22:39 UTC | |
|
Re: Object Destructors and Signals
by ikegami (Patriarch) on Nov 05, 2010 at 16:27 UTC | |
by bot403 (Beadle) on Nov 05, 2010 at 18:35 UTC | |
by ikegami (Patriarch) on Nov 05, 2010 at 18:46 UTC | |
by bot403 (Beadle) on Nov 05, 2010 at 19:41 UTC |