Jan Gehring > Rex > Rex::Transaction

Download:
Rex-0.54.3.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  4
Open  0
View/Report Bugs
Module Version: 0.54.3   Source   Latest Release: Rex-0.55.0

NAME ^

Rex::Transaction - Transaction support.

DESCRIPTION ^

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

SYNOPSIS ^

 task "do-something", "server01", sub {
  on_rollback {
    rmdir "/tmp/mydata";
  };
 
  transaction {
    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"); }
  };
 };

EXPORTED FUNCTIONS ^

transaction($codeRef)

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/];
    };
 };
on_rollback($codeRef)

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

See transaction.

syntax highlighting: