Rex::Transaction(3pm)

Rex::Transaction3pm

Transaction support

Usage

 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'); }
   };
 };

Overview

With this module you can define transactions and rollback scenarios on failure.

Exported functions

transaction($codeRef)

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/];
   };
 };

on_rollback($codeRef)

This will execute $codeRef if a step in the transaction <https://metacpan.org/pod/Rex::Transaction#transaction> fails.

Releases

5 releases since Debian 9 (Stretch); the text changed 4 times.

  1. 9
  2. 10
  3. 11
  4. 12
  5. 13

From rex 1.16.0-1 in Debian 13 (Trixie). Parsed by carta from the page's man source.