1Rex::Transaction(3) User Contributed Perl Documentation Rex::Transaction(3)
2
3
4
6 Rex::Transaction - Transaction support
7
9 With this module you can define transactions and rollback scenarios on
10 failure.
11
13 use Rex::Transaction;
14
15 task 'do-something', 'server01', sub {
16 transaction {
17 on_rollback {
18 rmdir '/tmp/mydata';
19 };
20
21 mkdir '/tmp/mydata';
22 upload 'files/myapp.tar.gz', '/tmp/mydata';
23 run 'tar xzf myapp.tar.gz -C /tmp/mydata';
24 if ( $? != 0 ) { die('Error extracting myapp.tar.gz'); }
25 };
26 };
27
29 transaction($codeRef)
30 Start a transaction for $codeRef. If $codeRef dies, Rex will run the
31 on_rollback <https://metacpan.org/pod/Rex::Transaction#on_rollback>
32 code to roll back the transaction.
33
34 task 'deploy', group => 'frontend', sub {
35 on_rollback {
36 rmdir '...';
37 };
38
39 deploy 'myapp.tar.gz';
40 };
41
42 task 'restart_server', group => 'frontend', sub {
43 service apache2 => 'restart';
44 };
45
46 task 'all', group => 'frontend', sub {
47 transaction {
48 do_task [qw/deploy restart_server/];
49 };
50 };
51
52 on_rollback($codeRef)
53 This will execute $codeRef if a step in the transaction
54 <https://metacpan.org/pod/Rex::Transaction#transaction> fails.
55
56
57
58perl v5.36.0 2022-07-20 Rex::Transaction(3)