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

Last change on this file since 1830 was 1830, checked in by nanardon, 8 years ago

Stat have to run even there is no change in database

  • Property svn:executable set to *
File size: 1.6 KB
Line 
1package LATMOS::Accounts::Task::Stats;
2
3use strict;
4use warnings;
5use base qw(LATMOS::Accounts::Task);
6use LATMOS::Accounts;
7use LATMOS::Accounts::Log;
8use LATMOS::Accounts::Utils;
9
10=head1 NAME
11
12LATMOS::Accounts::Task::Stats - Store value to perform some statistics
13
14=head1 DESCRIPTION
15
16=cut
17
18sub init {
19    my ($self) = @_;
20    my $LA = LATMOS::Accounts->new($self->{config}, noacl => 1);
21    my $labase = $self->{base} ? $LA->base($self->{base}) : $LA->base;
22    $labase && $labase->load or die "Cannot load base";
23
24    $self->{_la} = $LA;
25    $self->{_base} = $labase;
26
27    1;
28}
29
30sub waitDelay { 5 * 60 }
31
32sub needupd { 1; }
33
34sub run {
35    my ($self) = @_;
36
37    $self->{_base}->temp_switch_unexported(
38        sub {
39            foreach my $stat ($self->{_base}->list_objects('stat')) {
40                my $ostat = $self->{_base}->get_object('stat', $stat);
41                # Don't process unexported stat objects
42                $ostat->_get_attributes('unexported') and next;
43                if ($ostat->collect) {
44                    $self->{_base}->commit;
45                } else {
46                    $self->{_base}->rollback;
47                }
48            }
49        },
50        1
51    );
52
53    return 1;
54}
55
561;
57
58__END__
59
60=head1 SEE ALSO
61
62L<LATMOS::Accounts>, L<LATMOS::Accounts::Task>
63
64=head1 AUTHOR
65
66Olivier Thauvin, E<lt>olivier.thauvin@latmos.ipsl.frE<gt>
67
68=head1 COPYRIGHT AND LICENSE
69
70Copyright (C) 2012 CNRS SA/CETP/LATMOS
71
72This library is free software; you can redistribute it and/or modify
73it under the same terms as Perl itself, either Perl version 5.10.0 or,
74at your option, any later version of Perl 5 you may have available.
75
76=cut
77
Note: See TracBrowser for help on using the repository browser.