- open(my $fh, '>', $file) or die "Cannot open $file for writing: $!\n";
- print {$fh} $http->content;
- close($fh);
+ my ($http, $retry, $tries);
+ $http = undef;
+
+ do {
+ $retry = false;
+ $tries++;
+ eval {
+ $http = $mech->get($Config->{events_url});
+ } or do {
+ warn "[${\scalar localtime}] $@";
+ $retry = ($tries < $Config->{max_tries}) ? true : false;
+ sleep $Config->{sleep_secs} if $retry;
+ };
+ } while ($retry);
+
+ if (defined $http) {
+ open(my $fh, '>', $file) or die "Cannot open $file for writing: $!\n";
+ print {$fh} $http->content;
+ close($fh);
+ }
+ else {
+ my $script = File::Basename::basename($0);
+ warn "[${\scalar localtime}] $script not entirely run, no http content\n";
+ my $message = <<"MSG";
+hello,
+
+This is lreminder [<$Config->{mail_from}>].
+
+Could not run $script entirely, no http content.
+Please re-run manually with `$0 --run' today.
+
+thanks,
+MSG
+ sendmail(
+ From => $Config->{mail_from},
+ To => $Config->{mail_admin},
+ Subject => 'LUGS Reminder - warning: timeout',
+ Message => $message,
+ ) or die "Cannot send mail: $Mail::Sendmail::error";
+ exit;
+ }