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

Last change on this file since 2286 was 2016, checked in by nanardon, 7 years ago

Stat must be run at the end

  • 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 order { 2 }
31
32sub waitDelay { 5 * 60 }
33
34sub needupd { 1; }
35
36sub run {
37    my ($self) = @_;
38
39    $self->{_base}->temp_switch_unexported(
40        sub {
41            foreach my $stat ($self->{_base}->list_objects('stat')) {
42                my $ostat = $self->{_base}->get_object('stat', $stat);
43                # Don't process unexported stat objects
44                $ostat->_get_attributes('unexported') and next;
45                if ($ostat->collect) {
46                    $self->{_base}->commit;
47                } else {
48                    $self->{_base}->rollback;
49                }
50            }
51        },
52        1
53    );
54
55    return 1;
56}
57
581;
59
60__END__
61
62=head1 SEE ALSO
63
64L<LATMOS::Accounts>, L<LATMOS::Accounts::Task>
65
66=head1 AUTHOR
67
68Olivier Thauvin, E<lt>olivier.thauvin@latmos.ipsl.frE<gt>
69
70=head1 COPYRIGHT AND LICENSE
71
72Copyright (C) 2012 CNRS SA/CETP/LATMOS
73
74This library is free software; you can redistribute it and/or modify
75it under the same terms as Perl itself, either Perl version 5.10.0 or,
76at your option, any later version of Perl 5 you may have available.
77
78=cut
79
Note: See TracBrowser for help on using the repository browser.