Data-Downloader
view release on metacpan or search on metacpan
lib/Data/Downloader/DB.pm view on Meta::CPAN
my $class = shift;
# See Rose::DB -- this is the recommended way to cache db handles.
my $dbh = DBI->connect_cached(@_);
$dbh->do("PRAGMA synchronous = OFF");
$dbh->do("PRAGMA foreign_keys = ON") unless $ENV{DATA_DOWNLOADER_BULK_DOWNLOAD};
$dbh->do("PRAGMA count_changes = OFF");
if (my $mode = $ENV{DATA_DOWNLOADER_JOURNAL_MODE}) {
$dbh->do("PRAGMA journal_mode = $mode")
if (grep $_ eq $mode, qw(DELETE TRUNCATE PERSIST MEMORY WAL OFF));
}
$dbh->sqlite_busy_timeout(1000*300); # wait up to 5 minutes if it is locked
return $dbh;
}
=item simple
Returns a L<DBIx::Simple|DBIx::Simple> object, for when the ORM is not enough.
=cut
sub simple {
lib/Data/Downloader/File.pm view on Meta::CPAN
my $tries = 0;
my $success;
my $errors;
# For SQLite:
# Force an exclusive transaction. This is necessary when doing WAL
# journaling. Without this, the first statement, which is a select
# on symlinks will force a SHARED lock. When it then tries to DELETE
# the symlinks it will not be able to upgrade to an EXCLUSIVE lock
# if another process already has an EXCLUSIVE lock, so it will fail
# without doing the busy timeout.
local $self->db->dbh->{sqlite_use_immediate_transaction} = 1;
while (!$success && $tries++ < 10) {
$success = $self->db->do_transaction(sub {
if ($self->on_disk) {
for my $symlink ($self->symlinks) {
DEBUG "removing symlink ".$symlink->linkname;
-l $symlink->linkname and do {
unlink $symlink->linkname
or WARNDIE "failed to remove symlink ".$symlink->linkname." : $!";
( run in 0.330 second using v1.01-cache-2.11-cpan-87723dcf8b7 )