summaryrefslogtreecommitdiff
path: root/FS/bin
diff options
context:
space:
mode:
authorChristopher Burger <burgerc@freeside.biz>2018-03-13 10:20:06 -0400
committerChristopher Burger <burgerc@freeside.biz>2018-03-13 10:20:06 -0400
commite46f0ef0da8d0f639bacb293bfdf820e2a68b480 (patch)
treeac96c07b1d115b658b35c425e5de748c20c0698b /FS/bin
parentd41661cfbdcf4147342c83d3ed992f706abb92da (diff)
RT# 79780 - added a 60 second pause when there is a connection failure, then retry. Do this for 20 hours
Diffstat (limited to 'FS/bin')
-rw-r--r--FS/bin/freeside-ipifony-download38
1 files changed, 28 insertions, 10 deletions
diff --git a/FS/bin/freeside-ipifony-download b/FS/bin/freeside-ipifony-download
index 10faa74..09e83ea 100644
--- a/FS/bin/freeside-ipifony-download
+++ b/FS/bin/freeside-ipifony-download
@@ -104,16 +104,7 @@ if ( $opt{P} =~ /^(\d+)$/ ) {
}
# for now assume SFTP download as the only method
-print STDERR "Connecting to $sftpuser\@$host...\n" if $opt{v};
-
-my $sftp = Net::SFTP::Foreign->new(
- host => $host,
- user => $sftpuser,
- port => $port,
- # for now we don't support passwords. use authorized_keys.
- timeout => 30,
- #more => ($opt{v} ? '-v' : ''),
-);
+my $sftp = sftp_connect($host, $sftpuser, $port);
die "failed to connect to '$sftpuser\@$host'\n(".$sftp->error.")\n"
if $sftp->error;
@@ -289,6 +280,33 @@ Finished!
";
}
+sub sftp_connect {
+ my ($host, $sftpuser, $port) = @_;
+ my $sftp;
+ my $connection_tries = 1;
+
+ while (1) {
+ print STDERR "Connecting to $sftpuser\@$host try number $connection_tries...\n" if $opt{v};
+ $sftp = Net::SFTP::Foreign->new(
+ host => $host,
+ user => $sftpuser,
+ port => $port,
+ # for now we don't support passwords. use authorized_keys.
+ timeout => 30,
+ #more => ($opt{v} ? '-v' : ''),
+ );
+
+ if ($sftp->error && $connection_tries < 1200) {
+ $connection_tries++;
+ print STDERR "Connection failed to $sftpuser\@$host trying again in 60 sec...\n" if $opt{v};
+ sleep 60;
+ }
+ else { last; }
+ }
+
+ return $sftp
+}
+
=head1 NAME
freeside-ipifony-download - Download and import invoice items from IPifony.