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

Last change on this file since 1503 was 1427, checked in by nanardon, 9 years ago

Add a statistics collecting functions

File size: 2.2 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 config($value, $default)
40
41Return config value for the module
42
43=cut
44
45sub config {
46    my ($self, $value, $default) = @_;
47
48    return $self->{syncm}->ini->val($self->{name}, $value, $default)
49}
50
51=head2 init
52
53Call at task startup, can be overload
54
55=cut
56
57sub init {
58    return 1;
59}
60
61=head2 needupd($baserev, $syncm)
62
63This function is to call to check if the module have to run or not.
64
65C<$baserev> is the current base revision en C<$syncm> the revision when
66la-sync-manager was run.
67
68By default return true only if base has changed, overload for different
69behavior.
70
71=cut
72
73sub needupd {
74    my ($self, $lastrev, $currentrev) = @_;
75
76    la_log LA_DEBUG, "Comparing db: %d <=> %d", $currentrev, $lastrev;
77    if ($currentrev > $lastrev) {
78        return 1;
79    } else {
80        la_log LA_DEBUG, "No change in DB, doing nothing";
81        return;
82    }
83}
84
85=head2 run
86
87Must be provided by module, do the desired work.
88
89=cut
90
91sub run {
92    return 1;
93}
94
95=head2 post
96
97Call after C<run()>
98
99=cut
100
101sub post {
102}
103
104=head2 reset_savepoint
105
106Reset the savepoint to 0 to force the module to be run again
107
108=cut
109
110sub reset_savepoint {
111    return 1;
112}
113
1141;
115
116__END__
117
118=head1 SEE ALSO
119
120L<LATMOS::Accounts::SyncManager>
121
122=head1 AUTHOR
123
124Thauvin Olivier, E<lt>olivier.thauvin@latmos.ipsl.frE<gt>
125
126=head1 COPYRIGHT AND LICENSE
127
128Copyright (C) 2009, 2010, 2011, 2012 by Thauvin Olivier
129
130This library is free software; you can redistribute it and/or modify
131it under the same terms as Perl itself, either Perl version 5.10.0 or,
132at your option, any later version of Perl 5 you may have available.
133
134=cut
Note: See TracBrowser for help on using the repository browser.