| | 89 | # Check if this plugin has to be updated |
|---|
| | 90 | my $update_rate = get_global_service_value(\%service_config, $plugin, "update_rate", 0); |
|---|
| | 91 | my ($update_rate_in_seconds, $is_update_discrete) = parse_update_rate($update_rate); |
|---|
| | 92 | # default is 0 sec : always update when asked |
|---|
| | 93 | DEBUG "[DEBUG] update_rate $update_rate_in_seconds for $plugin on $nodedesignation"; |
|---|
| | 94 | if ($update_rate_in_seconds |
|---|
| | 95 | && is_fresh_enough($nodedesignation, $plugin, $update_rate_in_seconds)) { |
|---|
| | 96 | # It's fresh enough, skip this $service |
|---|
| | 97 | DEBUG "[DEBUG] $plugin is fresh enough, not updating it"; |
|---|
| | 98 | next; |
|---|
| | 99 | } |
|---|
| | 100 | |
|---|
| 90 | | # Check if this plugin has to be updated |
|---|
| 91 | | my $update_rate_in_seconds = get_global_service_value(\%service_config, $plugin, "update_rate", 0); # default is 0 sec : always update when asked |
|---|
| 92 | | DEBUG "[DEBUG] update_rate $update_rate_in_seconds for $plugin on $nodedesignation"; |
|---|
| 93 | | if ($update_rate_in_seconds |
|---|
| 94 | | && is_fresh_enough($nodedesignation, $plugin, $update_rate_in_seconds)) { |
|---|
| 95 | | # It's fresh enough, skip this $service |
|---|
| 96 | | DEBUG "[DEBUG] $plugin is fresh enough, not updating it"; |
|---|
| 97 | | next; |
|---|
| | 102 | %service_data = $self->{node}->fetch_service_data($plugin); |
|---|
| | 103 | } |
|---|
| | 104 | |
|---|
| | 105 | # If update_rate is discrete, round the "when" for granularity |
|---|
| | 106 | if ($is_update_discrete) { |
|---|
| | 107 | foreach my $service (keys %service_data) { |
|---|
| | 108 | my $current_service_data = $service_data{$service}; |
|---|
| | 109 | foreach my $field (keys %$current_service_data) { |
|---|
| | 110 | my $when = $current_service_data->{$field}->{when}; |
|---|
| | 111 | my $rounded_when = round_to_granularity($when, $update_rate_in_seconds); |
|---|
| | 112 | $current_service_data->{$field}->{when} = $rounded_when; |
|---|
| | 113 | } |
|---|
| | 227 | sub parse_update_rate { |
|---|
| | 228 | my ($update_rate_config) = @_; |
|---|
| | 229 | #$update_rate_config = $config->_trim($update_rate_config); |
|---|
| | 230 | |
|---|
| | 231 | my ($is_update_discrete, $update_rate_in_sec); |
|---|
| | 232 | if ($update_rate_config =~ m/(\d+[a-z]?) (discrete)?/) { |
|---|
| | 233 | $update_rate_in_sec = to_sec($1); |
|---|
| | 234 | $is_update_discrete = $2; |
|---|
| | 235 | } else { |
|---|
| | 236 | return (0, 0); |
|---|
| | 237 | } |
|---|
| | 238 | |
|---|
| | 239 | return ($update_rate_in_sec, $is_update_discrete); |
|---|
| | 240 | } |
|---|
| | 241 | |
|---|
| | 242 | sub round_to_granularity { |
|---|
| | 243 | my ($when, $granularity_in_sec) = @_; |
|---|
| | 244 | $when = time if ($when eq "N"); # N means "now" |
|---|
| | 245 | |
|---|
| | 246 | my $rounded_when = $when - ($when % $granularity_in_sec); |
|---|
| | 247 | return $rounded_when; |
|---|
| | 248 | } |
|---|
| | 249 | |
|---|