Open the DB using Hydra::Model::DB->new
This gets rid of the openHydraDB function and ensures that we open the database in a consistent way. Also drop the PostgreSQL sequence hacks. They don't seem to be necessary anymore.
This commit is contained in:
parent
914c5e248a
commit
179b012a8e
|
@ -6,6 +6,7 @@ use XML::Simple;
|
|||
use POSIX qw(strftime);
|
||||
use IPC::Run;
|
||||
use Nix::Store;
|
||||
use Hydra::Model::DB;
|
||||
use Hydra::Helper::Nix;
|
||||
use Digest::SHA qw(sha256_hex);
|
||||
use File::Basename;
|
||||
|
@ -22,7 +23,7 @@ our @EXPORT = qw(
|
|||
|
||||
|
||||
sub scmPath {
|
||||
return getHydraPath . "/scm" ;
|
||||
return Hydra::Model::DB::getHydraPath . "/scm" ;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -5,23 +5,17 @@ use Exporter;
|
|||
use File::Path;
|
||||
use File::Basename;
|
||||
use Hydra::Helper::CatalystUtils;
|
||||
use Hydra::Model::DB;
|
||||
|
||||
our @ISA = qw(Exporter);
|
||||
our @EXPORT = qw(
|
||||
getHydraPath getHydraHome getHydraDBPath openHydraDB getHydraConf txn_do
|
||||
getHydraHome getHydraConf txn_do
|
||||
registerRoot getGCRootsDir gcRootFor
|
||||
getPrimaryBuildsForView
|
||||
getPrimaryBuildTotal
|
||||
getViewResult getLatestSuccessfulViewResult jobsetOverview removeAsciiEscapes);
|
||||
|
||||
|
||||
sub getHydraPath {
|
||||
my $dir = $ENV{"HYDRA_DATA"} || "/var/lib/hydra";
|
||||
die "The HYDRA_DATA directory ($dir) does not exist!\n" unless -d $dir;
|
||||
return $dir;
|
||||
}
|
||||
|
||||
|
||||
sub getHydraHome {
|
||||
my $dir = $ENV{"HYDRA_HOME"} or die "The HYDRA_HOME directory does not exist!\n";
|
||||
return $dir;
|
||||
|
@ -29,33 +23,12 @@ sub getHydraHome {
|
|||
|
||||
|
||||
sub getHydraConf {
|
||||
my $conf = $ENV{"HYDRA_CONFIG"} || (getHydraPath . "/hydra.conf");
|
||||
my $conf = $ENV{"HYDRA_CONFIG"} || (Hydra::Model::DB::getHydraPath . "/hydra.conf");
|
||||
die "The HYDRA_CONFIG file ($conf) does not exist!\n" unless -f $conf;
|
||||
return $conf;
|
||||
}
|
||||
|
||||
|
||||
sub getHydraDBPath {
|
||||
my $db = $ENV{"HYDRA_DBI"};
|
||||
if ( defined $db ) {
|
||||
return $db ;
|
||||
}
|
||||
else {
|
||||
my $path = getHydraPath . '/hydra.sqlite';
|
||||
die "The Hydra database ($path) not exist!\n" unless -f $path;
|
||||
return "dbi:SQLite:$path";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
sub openHydraDB {
|
||||
my $db = Hydra::Schema->connect(getHydraDBPath, "", "", {});
|
||||
$db->storage->dbh->do("PRAGMA synchronous = OFF;")
|
||||
if defined $ENV{'HYDRA_NO_FSYNC'};
|
||||
return $db;
|
||||
}
|
||||
|
||||
|
||||
# Awful hack to handle timeouts in SQLite: just retry the transaction.
|
||||
# DBD::SQLite *has* a 30 second retry window, but apparently it
|
||||
# doesn't work.
|
||||
|
|
|
@ -2,7 +2,20 @@ package Hydra::Model::DB;
|
|||
|
||||
use strict;
|
||||
use base 'Catalyst::Model::DBIC::Schema';
|
||||
use Hydra::Helper::Nix;
|
||||
|
||||
sub getHydraPath {
|
||||
my $dir = $ENV{"HYDRA_DATA"} || "/var/lib/hydra";
|
||||
die "The HYDRA_DATA directory ($dir) does not exist!\n" unless -d $dir;
|
||||
return $dir;
|
||||
}
|
||||
|
||||
sub getHydraDBPath {
|
||||
my $db = $ENV{"HYDRA_DBI"};
|
||||
return $db if defined $db;
|
||||
my $path = getHydraPath . '/hydra.sqlite';
|
||||
die "The Hydra database ($path) not exist!\n" unless -f $path;
|
||||
return "dbi:SQLite:$path";
|
||||
}
|
||||
|
||||
__PACKAGE__->config(
|
||||
schema_class => 'Hydra::Schema',
|
||||
|
|
|
@ -156,16 +156,4 @@ __PACKAGE__->belongs_to(
|
|||
# Created by DBIx::Class::Schema::Loader v0.07014 @ 2011-12-05 14:15:43
|
||||
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:yaqa9gcGx9Z+Nfr3xgX28g
|
||||
|
||||
use Hydra::Helper::Nix;
|
||||
|
||||
sub addSequence {
|
||||
my $hydradbi = getHydraDBPath ;
|
||||
if ($hydradbi =~ m/^dbi:Pg/) {
|
||||
__PACKAGE__->sequence('builds_id_seq');
|
||||
}
|
||||
}
|
||||
|
||||
addSequence ;
|
||||
|
||||
# You can replace this text with custom content, and it will be preserved on regeneration
|
||||
1;
|
||||
|
|
|
@ -432,8 +432,6 @@ __PACKAGE__->has_many(
|
|||
# Created by DBIx::Class::Schema::Loader v0.07014 @ 2012-02-29 18:56:22
|
||||
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:w16c86FRReLPdA8H0yTIRg
|
||||
|
||||
use Hydra::Helper::Nix;
|
||||
|
||||
__PACKAGE__->has_many(
|
||||
"dependents",
|
||||
"Hydra::Schema::BuildInputs",
|
||||
|
@ -456,13 +454,6 @@ __PACKAGE__->has_one(
|
|||
},
|
||||
);
|
||||
|
||||
sub addSequence {
|
||||
my $hydradbi = getHydraDBPath;
|
||||
if ($hydradbi =~ m/^dbi:Pg/) {
|
||||
__PACKAGE__->sequence('builds_id_seq');
|
||||
}
|
||||
}
|
||||
|
||||
sub makeSource {
|
||||
my ($name, $query) = @_;
|
||||
my $source = __PACKAGE__->result_source_instance();
|
||||
|
@ -526,8 +517,6 @@ QUERY
|
|||
);
|
||||
}
|
||||
|
||||
addSequence;
|
||||
|
||||
makeQueries('', "");
|
||||
makeQueries('ForProject', "and project = ?");
|
||||
makeQueries('ForJobset', "and project = ? and jobset = ?");
|
||||
|
|
|
@ -145,14 +145,6 @@ __PACKAGE__->belongs_to("project", "Hydra::Schema::Projects", { name => "project
|
|||
# Created by DBIx::Class::Schema::Loader v0.07014 @ 2011-12-05 14:15:43
|
||||
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:eQtF5bcR/qZ625LxWBc7ug
|
||||
|
||||
use Hydra::Helper::Nix;
|
||||
|
||||
# !!! Ugly, should be generated.
|
||||
my $hydradbi = getHydraDBPath;
|
||||
if ($hydradbi =~ m/^dbi:Pg/) {
|
||||
__PACKAGE__->sequence('jobsetevals_id_seq');
|
||||
}
|
||||
|
||||
__PACKAGE__->has_many(
|
||||
"buildIds",
|
||||
"Hydra::Schema::JobsetEvalMembers",
|
||||
|
|
|
@ -86,12 +86,4 @@ __PACKAGE__->belongs_to("author", "Hydra::Schema::Users", { username => "author"
|
|||
# Created by DBIx::Class::Schema::Loader v0.07014 @ 2011-12-05 14:15:43
|
||||
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:YRMh0QI4JezFLj7nywGu6Q
|
||||
|
||||
use Hydra::Helper::Nix;
|
||||
|
||||
# !!! Ugly, should be generated.
|
||||
my $hydradbi = getHydraDBPath;
|
||||
if ($hydradbi =~ m/^dbi:Pg/) {
|
||||
__PACKAGE__->sequence('newsitems_id_seq');
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -6,6 +6,7 @@ use File::stat;
|
|||
use Nix::Store;
|
||||
use Hydra::Schema;
|
||||
use Hydra::Helper::Nix;
|
||||
use Hydra::Model::DB;
|
||||
use Hydra::Helper::AddBuilds;
|
||||
use Email::Sender::Simple qw(sendmail);
|
||||
use Email::Sender::Transport::SMTP;
|
||||
|
@ -21,7 +22,7 @@ use feature qw/switch/;
|
|||
|
||||
STDOUT->autoflush();
|
||||
|
||||
my $db = openHydraDB;
|
||||
my $db = Hydra::Model::DB->new();
|
||||
|
||||
|
||||
my %config = new Config::General(getHydraConf)->getall;
|
||||
|
|
|
@ -5,8 +5,8 @@ use feature 'switch';
|
|||
use Hydra::Schema;
|
||||
use Hydra::Helper::Nix;
|
||||
use Hydra::Helper::AddBuilds;
|
||||
use Hydra::Model::DB;
|
||||
use Digest::SHA qw(sha256_hex);
|
||||
|
||||
use Email::Sender::Simple qw(sendmail);
|
||||
use Email::Sender::Transport::SMTP;
|
||||
use Email::Simple;
|
||||
|
@ -17,7 +17,7 @@ use Data::Dump qw(dump);
|
|||
|
||||
STDOUT->autoflush();
|
||||
|
||||
my $db = openHydraDB;
|
||||
my $db = Hydra::Model::DB->new();
|
||||
my %config = new Config::General(getHydraConf)->getall;
|
||||
|
||||
|
||||
|
|
|
@ -3,11 +3,12 @@
|
|||
use strict;
|
||||
use Hydra::Schema;
|
||||
use Hydra::Helper::Nix;
|
||||
use Hydra::Model::DB;
|
||||
use File::Slurp;
|
||||
use SQL::SplitStatement;
|
||||
use List::Util qw(max);
|
||||
|
||||
my $db = openHydraDB;
|
||||
my $db = Hydra::Model::DB->new();
|
||||
my $dbh = $db->storage->dbh;
|
||||
$dbh->{RaiseError} = 1;
|
||||
|
||||
|
|
|
@ -6,11 +6,12 @@ use File::Basename;
|
|||
use POSIX qw(dup2 :sys_wait_h);
|
||||
use Hydra::Schema;
|
||||
use Hydra::Helper::Nix;
|
||||
use Hydra::Model::DB;
|
||||
use IO::Handle;
|
||||
use Nix::Store;
|
||||
|
||||
chdir getHydraPath or die;
|
||||
my $db = openHydraDB;
|
||||
chdir Hydra::Model::DB::getHydraPath or die;
|
||||
my $db = Hydra::Model::DB->new();
|
||||
|
||||
STDOUT->autoflush();
|
||||
|
||||
|
|
|
@ -6,9 +6,10 @@ use File::Basename;
|
|||
use Nix::Store;
|
||||
use Hydra::Schema;
|
||||
use Hydra::Helper::Nix;
|
||||
use Hydra::Model::DB;
|
||||
use POSIX qw(strftime);
|
||||
|
||||
my $db = openHydraDB;
|
||||
my $db = Hydra::Model::DB->new();
|
||||
|
||||
|
||||
my %roots;
|
||||
|
@ -75,7 +76,7 @@ foreach my $project ($db->resultset('Projects')->search({}, { order_by => ["name
|
|||
|
||||
# If the jobset has been disabled for more than one week, than
|
||||
# don't keep its builds anymore.
|
||||
if ($jobset->enabled == 0 && (time() - $jobset->lastcheckedtime > (7 * 24 * 3600))) {
|
||||
if ($jobset->enabled == 0 && (time() - ($jobset->lastcheckedtime || 0) > (7 * 24 * 3600))) {
|
||||
print STDERR "*** skipping disabled jobset ", $project->name, ":", $jobset->name, "\n";
|
||||
next;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue