I have two subs in my program one, selects a list of urls to work on and
then the next sub updates the selected url's because I am running fork and
don't want another process to check out the same url's thus causing things
to go crazy.

But my problem is that while this was good intentioned, it's not quick
enough. By the time one sub has checked out the url's and the next sub has
updated them to try and prevent them from being checked out again another
child process has already run the first select query and gotten the same
list of URLs.

So how can I add the update to the initial select?

Any help would be appreciated.

Zack


sub select_url() {

my $select_query = "SELECT check.url_id, check.url_timeout,
url.url_protocol, url.url, url.contact_ids, MD5.MD5, check.mc_id,
check.lc_status, check.lc_MD5_status
                      FROM monitor_check check
                      LEFT OUTER JOIN monitor_url url
                      ON check.url_id = url.url_id
                      LEFT OUTER JOIN monitor_MD5 MD5
                      ON check.url_id = MD5.url_id
                      WHERE ((active = 1)
                      AND ((chk_freq + UNIX_TIMESTAMP(lc_epoch)) <= ?))
                      OR (lc_status = 0)";

  my $url_list = $dbh->selectall_arrayref($select_query, undef,
$current_time)
        or die "Can't execute statement: $DBI::errstr";


  return($url_list);

}

sub temp_update_lc_epoch {

        my $arrcount2;

        foreach my $url (@$url_list) {

        $arrcount2++;


        my ($url_id) = (@$url[0]);
        my ($ctime) = time();

        my @update_values = ($ctime,$url_id);

        my $update_query_statement = "UPDATE monitor_check
                                      SET lc_epoch = FROM_UNIXTIME(?)
                                      WHERE url_id = ?";
        my $update_query = $dbh->prepare($update_query_statement)
            or die "Unable to prepare update_query: $DBI::errstr";

        my $update = $update_query->execute(@update_values)
            or die "Unable to execute update_query: $DBI::errstr";

        }
        open(LOG,">>./saint.log");
flock(LOG, 2);
        print LOG "Total URL's updated $arrcount2\n";
close(LOG);
}


Reply via email to