comparison Lib/Deployment/Batch/Generic.pm @ 0:03e58a454b20

Создан репозитарий
author Sergey
date Tue, 14 Jul 2009 12:54:37 +0400
parents
children 16ada169ca75
comparison
equal deleted inserted replaced
-1:000000000000 0:03e58a454b20
1 use strict;
2 package Deployment::Batch;
3 our @history;
4
5 package Deployment::Batch::Generic;
6 use Common;
7 use Time::HiRes;
8 our @ISA = qw(Object);
9
10 BEGIN {
11 DeclareProperty isProcessed => ACCESS_READ;
12 DeclareProperty LastError => ACCESS_READ;
13 DeclareProperty LocalHistory => ACCESS_NONE;
14 }
15
16 sub _Run {
17 my ($this) = @_;
18
19 undef $@;
20 local @history = ();
21 my $t0 = [Time::HiRes::gettimeofday];
22 eval {
23 $this->Run;
24 };
25 $this->Log("completed in ",Time::HiRes::tv_interval($t0)," s");
26
27 if ($@) {
28 $this->{$LastError} = $@;
29 Deployment::Batch::Rollback; # rallback nested actions
30 return 0;
31 }
32
33 $this->{$LocalHistory} = \@history;
34 $this->{$isProcessed} = 1;
35
36 return 1;
37 }
38
39 sub Name {
40 my $this = shift;
41 (my $mod = ref $this) =~ s/^(?:\w+\:\:)*(\w+)$/$1/;
42 return $mod;
43 }
44
45 sub _Rollback {
46 my ($this) = @_;
47
48 undef $@;
49 eval {
50 $this->Rollback;
51 };
52
53 if ($@) {
54 $this->{$LastError} = $@;
55 }
56
57 $this->{$isProcessed} = 0;
58
59 if ($this->{$LocalHistory}) {
60 local @history = @{$this->{$LocalHistory}};
61 Deployment::Batch::Rollback;
62 }
63
64 return 1;
65 }
66
67 sub Context {
68 my $this = shift;
69
70 return \%Deployment::Batch::Context;
71 }
72
73 sub Log {
74 my $this = shift @_;
75 if ($this->Context->{LogOutput}) {
76 my $out = $this->Context->{LogOutput};
77 print $out $this->Name,": ",@_,"\n";
78 }
79 }
80
81 sub Run {
82 }
83
84 sub Rollback {
85 }
86
87 1;