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