summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Steven Schubiger <stsc@refcnt.org>2016-01-11 13:48:31 +0100
committerGravatar Steven Schubiger <stsc@refcnt.org>2016-01-11 13:48:31 +0100
commit990582d3ffc09369b8f85b6b8e37a3959778f34e (patch)
treef62f1e08c00499d13c6cb8543135f225cdd69f23
parent4069e4a7585b2f77c626bb18d3d257dd49832d4c (diff)
downloadlugs-990582d3ffc09369b8f85b6b8e37a3959778f34e.tar.gz
lugs-990582d3ffc09369b8f85b6b8e37a3959778f34e.tar.bz2
lreminder: retry after timeout
-rwxr-xr-xlreminder/reminder.pl34
1 files changed, 28 insertions, 6 deletions
diff --git a/lreminder/reminder.pl b/lreminder/reminder.pl
index b3658ca..eb9d794 100755
--- a/lreminder/reminder.pl
+++ b/lreminder/reminder.pl
@@ -15,7 +15,7 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# Author: Steven Schubiger <stsc@refcnt.org>
-# Last modified: Tue Jan 6 14:37:04 CET 2015
+# Last modified: Fri Jan 8 12:43:13 CET 2016
use strict;
use warnings;
@@ -37,7 +37,7 @@ use Text::Wrap::Smart::XS qw(fuzzy_wrap);
use URI ();
use WWW::Mechanize ();
-my $VERSION = '0.50';
+my $VERSION = '0.51';
#-----------------------
# Start of configuration
@@ -50,6 +50,8 @@ my $Config = {
dbase_name => '<hidden>',
dbase_user => '<hidden>',
dbase_pass => '<hidden>',
+ sleep_secs => 300,
+ max_tries => 48,
};
#---------------------
@@ -89,11 +91,31 @@ sub getopts
sub fetch_and_write_events
{
my $mech = WWW::Mechanize->new;
- my $http = $mech->get($Config->{events_url});
- 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 {
+ warn "[${\scalar localtime}] ${\File::Basename::basename($0)} not entirely run, no http content\n";
+ exit;
+ }
}
sub init