commit c6d33cb1737c7393c3875752866ceb29ecb2a3df
parent 14237ff3f6ca4bfe4517b3a13896580b1f7221a4
Author: Kyle Milz <kyle@getaddrinfo.net>
Date: Sun, 8 Feb 2015 19:20:21 -0700
price_scraper: be more careful with product selection
Diffstat:
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/price_scraper.pl b/price_scraper.pl
@@ -29,6 +29,11 @@ my $cutoff = time - (30 * 24 * 60 * 60);
my $sql = "select part_num, manufacturer from products " .
"where last_seen > $cutoff order by last_scraped asc";
my ($part_num, $manufacturer) = $dbh->selectrow_array($sql);
+
+# prevent races with other scrapers, claim ownership as soon as possible
+$dbh->do("update products set last_scraped = ? where part_num = ?",
+ undef, time, $part_num);
+
if ($args{p} && $args{m}) {
$part_num = $args{p};
$manufacturer = $args{m};
@@ -124,11 +129,6 @@ printf $log "%s %-10s %-20s [%s] (%i s)\n", $timestamp, $manufacturer,
$part_num, join("", @status), time - $start;
close $log;
-
-# record that we finished scraping this product
-$dbh->do("update products set last_scraped = ? where part_num = ?",
- undef, time, $part_num);
-
$dbh->disconnect();
exit 0;