Rex::Transaction(3)
β¨ Rex::Transaction(3) β the Rex::Transaction era β¨
okay so real talk: this is Rex::Transaction, straight out of the User Contributed Perl Documentation section of the manual, and it's giving undo button for your whole deploy π
bestie, it's literally transaction support, iykyk.
πΈ NAME πΈ
Rex::Transaction β transaction support, no cap π
π¦ DESCRIPTION π¦
okay so here's the whole vibe: with this module you can define transactions and rollback scenarios for when stuff goes wrong on failure. that's it, that's the pitch. if your task face-plants, you get to clean up after it instead of leaving chaos everywhere πβ¨
π SYNOPSIS π
here's the whole thing in action, copy it exactly bestie:
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'); }
};
};
like, look at it. mkdir, upload, run, and if the $? isn't 0 it dies β and dying is exactly what kicks the rollback into gear π₯
π EXPORTED FUNCTIONS π
π transaction($codeRef) π
this one starts a transaction for $codeRef π«Ά. and here's the important bit: if $codeRef dies, Rex will run the on_rollback code to roll the whole transaction back. that's the deal. no cap.
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/];
};
};
see how deploy and restart_server are just sitting there living their lives, and then transaction wraps do_task [qw/deploy restart_server/] so the whole group either slays together or rolls back together? main character energy π
π§ on_rollback($codeRef) π§
this will execute $codeRef if a step in the transaction fails π. it's the cleanup crew, the safety net, the "okay we tried, let's put the furniture back" moment. iconic.
β lowkey important: the rollback only kicks in on failure β that's literally what it's for. define youron_rollbackinside thetransactionblock and let it handle the mess π
and that's the whole page bestie, go forth and transact responsibly π
this cutie pie of a manpage is brought to you by perl v5.42.3, dated 2023-08-05, and documented as Rex::Transaction(3) β take care, mwah ππ
π¦ where this page comes from
- nixos 26.05: perl5.42.3-Rex 1.14.3
- nixpkgs unstable: perl5.42.3-Rex 1.14.3
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms