DOKK / manpages / debian 10 / rex / Rex::Transaction.3pm.en
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.

 task "do-something", "server01", sub {
   transaction {
     on_rollback {
       rmdir "/tmp/mydata";
     };
 
     mkdir "/tmp/mydata";
     upload "files/myapp.tar.gz", "/tmp/mydata";
     run "cd /tmp/mydata; tar xzf myapp.tar.gz";
     if($? != 0) { die("Error extracting myapp.tar.gz"); }
   };
 };

Start a transaction for $codeRef. If $codeRef dies it will rollback the transaction.

 task "deploy", group => "frontend", sub {
    on_rollback {
      rmdir "...";
    };
    deploy "myapp.tar.gz";
 };
  
 task "restart_server", group => "frontend", sub {
    run "/etc/init.d/apache2 restart";
 };
  
 task "all", group => "frontend", sub {
    transaction {
      do_task [qw/deploy restart_server/];
    };
 };

This code will be executed if one step in the transaction fails.

See transaction.

2018-02-01 perl v5.26.1