Rex::Transaction(3pm) | User Contributed Perl Documentation | Rex::Transaction(3pm) |
Rex::Transaction - Transaction support
With this module you can define transactions and rollback scenarios on failure.
use Rex::Transaction; task 'do-something', 'server01', sub { transaction { on_rollback { rmdir '/tmp/mydata'; }; mkdir '/tmp/mydata'; upload 'files/myapp.tar.gz', '/tmp/mydata'; run 'tar xzf myapp.tar.gz -C /tmp/mydata'; if ( $? != 0 ) { die('Error extracting myapp.tar.gz'); } }; };
Start a transaction for $codeRef. If $codeRef dies, Rex will run the on_rollback <https://metacpan.org/pod/Rex::Transaction#on_rollback> code to roll back the transaction.
task 'deploy', group => 'frontend', sub { on_rollback { rmdir '...'; }; deploy 'myapp.tar.gz'; }; task 'restart_server', group => 'frontend', sub { service apache2 => 'restart'; }; task 'all', group => 'frontend', sub { transaction { do_task [qw/deploy restart_server/]; }; };
This will execute $codeRef if a step in the transaction <https://metacpan.org/pod/Rex::Transaction#transaction> fails.
2021-03-05 | perl v5.32.1 |