source: trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Task.pm @ 1315

Last change on this file since 1315 was 1206, checked in by nanardon, 11 years ago

use 'savepoint' word instead checkpoint

File size: 2.0 KB
Line 
1package LATMOS::Accounts::Task;
2
3use strict;
4use warnings;
5use LATMOS::Accounts::Log;
6
7=head1 NAME
8
9    LATMOS::Accounts::Task
10
11=head1 DESCRIPTION
12
13Parent class for regular task run by L<la-sync-manager>
14
15=head1 FUNCTIONS
16
17=head2 new($module, %options)
18
19Instanciate a new task of type C<$module>
20
21The module must provide a C<_new()> function.
22
23=cut
24
25sub 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
34sub _new {
35    my ($class, %options) = @_;
36    bless { %options }, $class;
37}
38
39=head2 init
40
41Call at task startup, can be overload
42
43=cut
44
45sub init {
46    return 1;
47}
48
49=head2 needupd($baserev, $syncm)
50
51This function is to call to check if the module have to run or not.
52
53C<$baserev> is the current base revision en C<$syncm> the revision when
54la-sync-manager was run.
55
56By default return true only if base has changed, overload for different
57behavior.
58
59=cut
60
61sub 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
75Must be provided by module, do the desired work.
76
77=cut
78
79sub run {
80    return 1;
81}
82
83=head2 post
84
85Call after C<run()>
86
87=cut
88
89sub post {
90}
91
92=head2 reset_savepoint
93
94Reset the savepoint to 0 to force the module to be run again
95
96=cut
97
98sub reset_savepoint {
99    return 1;
100}
101
1021;
103
104__END__
105
106=head1 SEE ALSO
107
108L<LATMOS::Accounts::SyncManager>
109
110=head1 AUTHOR
111
112Thauvin Olivier, E<lt>olivier.thauvin@latmos.ipsl.frE<gt>
113
114=head1 COPYRIGHT AND LICENSE
115
116Copyright (C) 2009, 2010, 2011, 2012 by Thauvin Olivier
117
118This library is free software; you can redistribute it and/or modify
119it under the same terms as Perl itself, either Perl version 5.10.0 or,
120at your option, any later version of Perl 5 you may have available.
121
122=cut
Note: See TracBrowser for help on using the repository browser.