protected function ParserService::setNextAttempt in Weather 2.0.x
Same name and namespace in other branches
- 8 src/Service/ParserService.php \Drupal\weather\Service\ParserService::setNextAttempt()
Sets time for next download attempt.
Throws
\Drupal\Core\Entity\EntityStorageException
1 call to ParserService::setNextAttempt()
- ParserService::downloadWeather in src/
Service/ ParserService.php - Downloads forecast from yr.no and puts it do DB.
File
- src/
Service/ ParserService.php, line 501
Class
- ParserService
- Parsing of XML weather forecasts from yr.no.
Namespace
Drupal\weather\ServiceCode
protected function setNextAttempt($meta, $time) {
// The download did not succeed. Set next download attempt accordingly.
// Calculate the UTC timestamp.
$next_update = strtotime($meta['next_update'] . ' UTC');
// Initial retry after 675 seconds (11.25 minutes).
// This way, the doubling on the first day leads to exactly 86400
// seconds (one day) update interval.
$seconds_to_retry = 675;
while ($next_update + $seconds_to_retry <= $time) {
if ($seconds_to_retry < 86400) {
$seconds_to_retry = $seconds_to_retry * 2;
}
else {
$seconds_to_retry = $seconds_to_retry + 86400;
}
}
// Finally, calculate the UTC time of the next download attempt.
$meta['next_download_attempt'] = gmdate('Y-m-d H:i:s', $next_update + $seconds_to_retry);
$forecastInfo = $this->weatherForecastInfoStorage
->load($meta['geoid']);
if ($forecastInfo) {
$this->weatherForecastInfoStorage
->delete([
$forecastInfo,
]);
}
$this->weatherForecastInfoStorage
->create($meta)
->save();
}