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

Last change on this file since 1199 was 1019, checked in by nanardon, 12 years ago
  • Fix link
File size: 1.9 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, $baserev, $syncm) = @_;
63
64    $baserev ||= -1;
65    la_log LA_DEBUG, "Comparing db: %d <=> %d", $syncm->dbrev, $baserev;
66    if ($syncm->dbrev > $baserev) {
67        return 1;
68    } else {
69        la_log LA_DEBUG, "No change in DB, doing nothing";
70        return;
71    }
72}
73
74=head2 run
75
76Must be provided by module, do the desired work.
77
78=cut
79
80sub run {
81    return 1;
82}
83
84=head2 post
85
86Call after C<run()>
87
88=cut
89
90sub post {
91}
92
931;
94
95__END__
96
97=head1 SEE ALSO
98
99L<LATMOS::Accounts::SyncManager>
100
101=head1 AUTHOR
102
103Thauvin Olivier, E<lt>olivier.thauvin@latmos.ipsl.frE<gt>
104
105=head1 COPYRIGHT AND LICENSE
106
107Copyright (C) 2009, 2010, 2011, 2012 by Thauvin Olivier
108
109This library is free software; you can redistribute it and/or modify
110it under the same terms as Perl itself, either Perl version 5.10.0 or,
111at your option, any later version of Perl 5 you may have available.
112
113=cut
Note: See TracBrowser for help on using the repository browser.