1 | package LATMOS::Accounts::Task; |
---|
2 | |
---|
3 | use strict; |
---|
4 | use warnings; |
---|
5 | use LATMOS::Accounts::Log; |
---|
6 | |
---|
7 | =head1 NAME |
---|
8 | |
---|
9 | LATMOS::Accounts::Task |
---|
10 | |
---|
11 | =head1 DESCRIPTION |
---|
12 | |
---|
13 | Parent class for regular task run by L<la-sync-manager> |
---|
14 | |
---|
15 | =head1 FUNCTIONS |
---|
16 | |
---|
17 | =head2 new($module, %options) |
---|
18 | |
---|
19 | Instanciate a new task of type C<$module> |
---|
20 | |
---|
21 | The module must provide a C<_new()> function. |
---|
22 | |
---|
23 | =cut |
---|
24 | |
---|
25 | sub new { |
---|
26 | my ($class, $module, %options) = @_; |
---|
27 | my $pclass = ucfirst(lc($module)); |
---|
28 | my $me = __PACKAGE__; |
---|
29 | eval "require ${me}::$pclass;"; |
---|
30 | if ($@) { return } # error message ? |
---|
31 | return "${me}::$pclass"->_new(%options); |
---|
32 | } |
---|
33 | |
---|
34 | sub _new { |
---|
35 | my ($class, %options) = @_; |
---|
36 | bless { %options }, $class; |
---|
37 | } |
---|
38 | |
---|
39 | =head2 init |
---|
40 | |
---|
41 | Call at task startup, can be overload |
---|
42 | |
---|
43 | =cut |
---|
44 | |
---|
45 | sub init { |
---|
46 | return 1; |
---|
47 | } |
---|
48 | |
---|
49 | =head2 needupd($baserev, $syncm) |
---|
50 | |
---|
51 | This function is to call to check if the module have to run or not. |
---|
52 | |
---|
53 | C<$baserev> is the current base revision en C<$syncm> the revision when |
---|
54 | la-sync-manager was run. |
---|
55 | |
---|
56 | By default return true only if base has changed, overload for different |
---|
57 | behavior. |
---|
58 | |
---|
59 | =cut |
---|
60 | |
---|
61 | sub needupd { |
---|
62 | my ($self, $lastrev, $currentrev) = @_; |
---|
63 | |
---|
64 | la_log LA_DEBUG, "Comparing db: %d <=> %d", $currentrev, $lastrev; |
---|
65 | if ($currentrev > $lastrev) { |
---|
66 | return 1; |
---|
67 | } else { |
---|
68 | la_log LA_DEBUG, "No change in DB, doing nothing"; |
---|
69 | return; |
---|
70 | } |
---|
71 | } |
---|
72 | |
---|
73 | =head2 run |
---|
74 | |
---|
75 | Must be provided by module, do the desired work. |
---|
76 | |
---|
77 | =cut |
---|
78 | |
---|
79 | sub run { |
---|
80 | return 1; |
---|
81 | } |
---|
82 | |
---|
83 | =head2 post |
---|
84 | |
---|
85 | Call after C<run()> |
---|
86 | |
---|
87 | =cut |
---|
88 | |
---|
89 | sub post { |
---|
90 | } |
---|
91 | |
---|
92 | =head2 reset_savepoint |
---|
93 | |
---|
94 | Reset the savepoint to 0 to force the module to be run again |
---|
95 | |
---|
96 | =cut |
---|
97 | |
---|
98 | sub reset_savepoint { |
---|
99 | return 1; |
---|
100 | } |
---|
101 | |
---|
102 | 1; |
---|
103 | |
---|
104 | __END__ |
---|
105 | |
---|
106 | =head1 SEE ALSO |
---|
107 | |
---|
108 | L<LATMOS::Accounts::SyncManager> |
---|
109 | |
---|
110 | =head1 AUTHOR |
---|
111 | |
---|
112 | Thauvin Olivier, E<lt>olivier.thauvin@latmos.ipsl.frE<gt> |
---|
113 | |
---|
114 | =head1 COPYRIGHT AND LICENSE |
---|
115 | |
---|
116 | Copyright (C) 2009, 2010, 2011, 2012 by Thauvin Olivier |
---|
117 | |
---|
118 | This library is free software; you can redistribute it and/or modify |
---|
119 | it under the same terms as Perl itself, either Perl version 5.10.0 or, |
---|
120 | at your option, any later version of Perl 5 you may have available. |
---|
121 | |
---|
122 | =cut |
---|