dgaramond2 has asked for the wisdom of the Perl Monks concerning the following question:
eval { TX: { # step 1: database $dbh->do("CREATE DATABASE foo"); push @undo, sub { $dbh->do("DROP DATABASE foo"); }; # step 2a: filesystem mkdir "/path/foo" or last TX; push @undo, sub { rmdir "/path/foo" }; # step 2b push @undo, sub { remove_tree "/path/foo" }; create_a_bunch_of_files_in("/path/foo") or last TX; # step 3: logger (usually also on filesystem) write_log("Database and files setup") or last TX; # step 4: email (it's okay to fail this step) send_email('foo@bar.com'); # mark success @undo = (); } # rollback, we force each step even though it dies for (reverse @undo) { eval { $_->() }; } };
Is there a module to do this sort of thing more clearly and correctly? In essence, I am changing different resources (filesystem, database, etc) in a number of steps. In the absense of a global transaction manager, the next best thing I can do is rollback/undo the previous steps should things go wrong in the middle.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Poor man's transaction construct
by ikegami (Patriarch) on Nov 24, 2010 at 03:23 UTC | |
by dgaramond2 (Monk) on Nov 24, 2010 at 12:21 UTC | |
by aquarium (Curate) on Nov 24, 2010 at 22:01 UTC | |
by ikegami (Patriarch) on Nov 24, 2010 at 16:34 UTC | |
|
Re: Poor man's transaction construct
by duelafn (Parson) on Nov 24, 2010 at 02:28 UTC | |
by dgaramond2 (Monk) on Nov 24, 2010 at 02:30 UTC | |
|
Re: Poor man's transaction construct
by aquarium (Curate) on Nov 24, 2010 at 01:55 UTC | |
|
Re: Poor man's transaction construct
by dgaramond2 (Monk) on Nov 24, 2010 at 02:44 UTC |