Create export dir and commit after session.

This commit is contained in:
hjp 2016-05-08 19:53:26 +00:00
parent d7446596d9
commit 6514b6cdb6
1 changed files with 6 additions and 3 deletions

View File

@ -239,6 +239,7 @@ sub release_fileset {
$self->log(3, "releasing fileset $target->{id}"); $self->log(3, "releasing fileset $target->{id}");
$self->{dbh}->do(q{update filesets set pid=null where id=? and pid=?}, {}, $target->{id}, $$); $self->{dbh}->do(q{update filesets set pid=null where id=? and pid=?}, {}, $target->{id}, $$);
$self->{dbh}->commit();
} }
@ -569,6 +570,7 @@ sub new_session {
sub close_session { sub close_session {
my ($self) = @_; my ($self) = @_;
$self->{dbh}->do("update sessions set end_date=? where id=?", {}, time(), $self->{session_id}); $self->{dbh}->do("update sessions set end_date=? where id=?", {}, time(), $self->{session_id});
$self->{dbh}->commit();
$self->close_file_connection; $self->close_file_connection;
delete $self->{target}; delete $self->{target};
} }
@ -827,6 +829,7 @@ sub export {
my ($self) = @_; my ($self) = @_;
my $dbh = $self->{dbh}; my $dbh = $self->{dbh};
my $exportdir = $self->basedir . "/export"; my $exportdir = $self->basedir . "/export";
mkdir($exportdir);
my $sessions = $dbh->selectcol_arrayref("select id from sessions order by id"); my $sessions = $dbh->selectcol_arrayref("select id from sessions order by id");
for my $session_id (@$sessions) { for my $session_id (@$sessions) {
@ -848,14 +851,14 @@ sub export {
and files.fileset=filesets.id and files.fileset=filesets.id
}); });
$sth->execute; $sth->execute;
open my $fh, '>', "$exportdir/$session_id.tsv.$$"; open my $fh, '>', "$exportdir/$session_id.tsv.$$" or die "cannot create $exportdir/$session_id.tsv.$$: $!";
print $fh join("\t", @{$sth->{NAME}}), "\n"; print $fh join("\t", @{$sth->{NAME}}), "\n";
while (my $r = $sth->fetchrow_arrayref) { while (my $r = $sth->fetchrow_arrayref) {
no warnings 'uninitialized'; no warnings 'uninitialized';
print $fh join("\t", @$r), "\n"; print $fh join("\t", @$r), "\n" or die "cannot write to $exportdir/$session_id.tsv.$$: $!";
} }
close($fh); close($fh);
rename "$exportdir/$session_id.tsv.$$", "$exportdir/$session_id.tsv"; rename "$exportdir/$session_id.tsv.$$", "$exportdir/$session_id.tsv" or die "cannot rename $exportdir/$session_id.tsv.$$ to $exportdir/$session_id.tsv: $!";
system "/bin/gzip", "$exportdir/$session_id.tsv"; system "/bin/gzip", "$exportdir/$session_id.tsv";
} }