source: trunk/LATMOS-Accounts/lib/LATMOS/Accounts/SyncManager.pm @ 1023

Last change on this file since 1023 was 1023, checked in by nanardon, 12 years ago
  • complete POD

This patch a basic documentation to all functions.
It also add two test to ensure all POD syntax are correct and coverage is full.

File size: 3.1 KB
Line 
1package LATMOS::Accounts::SyncManager;
2
3use strict;
4use warnings;
5use LATMOS::Accounts::Log;
6use LATMOS::Accounts;
7
8=head1 NAME
9
10LATMOS::Accounts::SyncManager - Routine task manager
11
12=head1 DESCRIPTION
13
14Handle Task process run by L<la-sync-manager>
15
16=head1 FUNCTIONS
17
18=cut
19
20=head2 new($config)
21
22Instaciate object.
23
24C<$config> is a path to an alternative configuration file to default one.
25
26=cut
27
28sub new {
29    my ($class, $config) = @_;
30
31    my $ini = Config::IniFiles->new(
32        -file => join('/', ($config || '/etc/latmos-accounts'),
33            'la-sync-manager.ini'),
34    ) or do {
35        la_log LA_ERR, "Cannot load config";
36        return;
37    };
38
39    bless {
40        ini => $ini,
41        config => $config,
42        lastrev => 0,
43    }, $class;
44}
45
46=head2 ini
47
48Return a reference to the L<Ini::Files> object handling configuration.
49
50=cut
51
52sub ini { $_[0]->{ini} }
53
54=head2 dbrev
55
56Return the current base revision
57
58=cut
59
60sub dbrev { $_[0]->{lastrev} }
61
62=head2 updrev
63
64Update status file with with current base revision as restart point
65
66=cut
67
68sub updrev {
69    my ($self) = @_;
70    my $LA = LATMOS::Accounts->new($self->{config}, noacl => 1);
71    my $base = $LA->default_base;
72    my $newrev = $base->current_rev;
73    $self->{lastrev} = $newrev;
74    return $newrev;
75}
76
77=head2 list_modules
78
79List configured task module
80
81=cut
82
83sub list_modules {
84    my ($self) = @_;
85    $self->ini->Sections;
86}
87
88=head2 process_module($module, $dbrev)
89
90Process C<$module>.
91
92=cut
93
94# TODO what is $dbrev, why is it need here ??
95
96sub process_module {
97    my ($self, $module, $dbrev) = @_;
98
99    eval {
100        if (!$self->ini->SectionExists($module)) {
101            la_log LA_ERR, "Cannot run inexistant module %s", $module;
102            return;
103        }
104
105        my $modtype = $self->ini->val($module, 'type', $module);
106        my $task = LATMOS::Accounts::Task->new(
107            $modtype,
108            config => $self->{config},
109        )
110            or do {
111            la_log(LA_ERR, 'Cannot load module %s', $modtype);
112            return;
113        };
114        la_log LA_NOTICE, "Processing sync module %s (%s)", $module, $modtype;
115        if (!$task->init) {
116            la_log(LA_ERR, 'init() failed for module %s', $module);
117            return;
118        }
119
120        if (!$task->needupd($dbrev, $self)) {
121            la_log LA_DEBUG, "No change on main base, aborting";
122            return 1;
123        }
124
125
126        my $res = $task->run;
127        if (!$res) {
128            la_log LA_ERR, "Task %s did not end successfully", $module;
129        }
130        $task->post if ($res);
131        la_log LA_DEBUG, "end process $module";
132        return $res;
133    };
134
135    if ($@) {
136        la_log(LA_CRIT, 'Fatal Perl Error: %s', $@);
137        return;
138    } else {
139        return 1;
140    }
141}
142
1431;
144
145__END__
146
147=head1 SEE ALSO
148
149L<LATMOS::Accountsi::Task>
150
151=head1 AUTHOR
152
153Olivier Thauvin, E<lt>olivier.thauvin@latmos.ipsl.frE<gt>
154
155=head1 COPYRIGHT AND LICENSE
156
157Copyright (C) 2012 CNRS SA/CETP/LATMOS
158
159This library is free software; you can redistribute it and/or modify
160it under the same terms as Perl itself, either Perl version 5.10.0 or,
161at your option, any later version of Perl 5 you may have available.
162
163=cut
Note: See TracBrowser for help on using the repository browser.