}
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).
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)) {
if (scalar @ready > 0) {
eval {
$dbh->{AutoCommit} = 1;
- run($dbh);
+ run($dbh, $ua);
$dbh->commit;
};
if ($@) {
} 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);
}