]> git.sesse.net Git - skvidarsync/commitdiff
Add connection keepalive.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 10 Nov 2023 21:51:00 +0000 (22:51 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 10 Nov 2023 21:51:00 +0000 (22:51 +0100)
bin/sync.pl

index 703b0c58d741b036ffbfed7425c804a345ddbaf1..0aea7b908a1f57d2e20441f9d66a2118fe93be62 100644 (file)
@@ -488,14 +488,12 @@ sub db_connect {
 }
 
 sub run {
-       my $dbh = shift;
+       my ($dbh, $ua) = @_;
        my $total_start = [Time::HiRes::gettimeofday];
 
        @log = ();
        skv_log("Siste sync startet: " . POSIX::ctime(time));
 
-       # Initialize the handles we need for communication.
-       my $ua = LWP::UserAgent->new('SKVidarLang/1.0');
        my $token = get_oauth_bearer_token($dbh, $ua);
 
        # Find the newest message, what it is linked to, and what was the one before it (for group diffing).
@@ -805,10 +803,12 @@ sub run {
        printf "Tok %.0f ms.\n", 1e3 * $elapsed;
 }
 
+# Initialize the handles we need for communication.
 my $dbh = db_connect() or die;
+my $ua = LWP::UserAgent->new(agent => 'SKVidarLang/1.0', keep_alive => 50);
 if ($#ARGV >= 0 && $ARGV[0] eq '--daemon') {
        # Start with a single, forced run.
-       run($dbh);
+       run($dbh, $ua);
 
        while (1) {
                while (!defined($dbh)) {
@@ -828,7 +828,7 @@ if ($#ARGV >= 0 && $ARGV[0] eq '--daemon') {
                if (scalar @ready > 0) {  
                        eval {
                                $dbh->{AutoCommit} = 1;
-                               run($dbh);
+                               run($dbh, $ua);
                                $dbh->commit;
                        };
                        if ($@) {
@@ -840,9 +840,9 @@ if ($#ARGV >= 0 && $ARGV[0] eq '--daemon') {
 } elsif ($#ARGV >= 0 && $ARGV[0] eq '--benchmark') {
        for my $i (0..9) {
                $dbh->{AutoCommit} = 1;
-               run($dbh);
+               run($dbh, $ua);
                $dbh->commit;
        }
 } else {
-       run($dbh);
+       run($dbh, $ua);
 }