Commit b7db4bdd authored by Francesc Guasch's avatar Francesc Guasch
Browse files

wip(requests): do not repeat cleanup requests

issue #838
parent b2fd93da
...@@ -106,7 +106,7 @@ our %COMMAND = ( ...@@ -106,7 +106,7 @@ our %COMMAND = (
} }
,priority => { ,priority => {
limit => 20 limit => 20
,commands => ['clone','start'] ,commands => ['clone','start','cleanup']
} }
); );
lock_hash %COMMAND; lock_hash %COMMAND;
...@@ -1049,6 +1049,7 @@ sub refresh_vms { ...@@ -1049,6 +1049,7 @@ sub refresh_vms {
my $class = ref($proto) || $proto; my $class = ref($proto) || $proto;
my $args = _check_args('refresh_vms', @_ ); my $args = _check_args('refresh_vms', @_ );
return if _requested('refresh_vms');
my $self = {}; my $self = {};
bless($self,$class); bless($self,$class);
...@@ -1110,6 +1111,8 @@ sub cleanup($proto , @args) { ...@@ -1110,6 +1111,8 @@ sub cleanup($proto , @args) {
my $args = _check_args('cleanup', @args ); my $args = _check_args('cleanup', @args );
return if _requested('cleanup');
my $self = {}; my $self = {};
bless ($self, $class); bless ($self, $class);
...@@ -1322,6 +1325,7 @@ sub enforce_limits { ...@@ -1322,6 +1325,7 @@ sub enforce_limits {
my $args = _check_args('enforce_limits', @_ ); my $args = _check_args('enforce_limits', @_ );
return if _requested('enforce_limits');
$args->{timeout} = $TIMEOUT_SHUTDOWN if !exists $args->{timeout}; $args->{timeout} = $TIMEOUT_SHUTDOWN if !exists $args->{timeout};
my $self = {}; my $self = {};
...@@ -1352,8 +1356,12 @@ This method is used for commands that take long to run as garbage collection. ...@@ -1352,8 +1356,12 @@ This method is used for commands that take long to run as garbage collection.
=cut =cut
sub done_recently { sub done_recently($self, $seconds=60,$command=undef) {
my ($self, $seconds) = @_; my $id_req = 0;
if ($self) {
$id_req = $self->id;
$command = $self->command;
}
my $sth = $$CONNECTOR->dbh->prepare( my $sth = $$CONNECTOR->dbh->prepare(
"SELECT id FROM requests" "SELECT id FROM requests"
." WHERE date_changed > ? " ." WHERE date_changed > ? "
...@@ -1363,11 +1371,24 @@ sub done_recently { ...@@ -1363,11 +1371,24 @@ sub done_recently {
." AND id <> ? " ." AND id <> ? "
); );
my $date= Time::Piece->localtime(time - $seconds); my $date= Time::Piece->localtime(time - $seconds);
$sth->execute($date->ymd." ".$date->hms, $self->command, $self->id); $sth->execute($date->ymd." ".$date->hms, $command, $id_req);
my ($id) = $sth->fetchrow; my ($id) = $sth->fetchrow;
return $id; return $id;
} }
sub _requested($command) {
_init_connector();
my $sth = $$CONNECTOR->dbh->prepare(
"SELECT id FROM requests"
." WHERE command = ? "
." AND status <> 'done' "
);
$sth->execute($command);
my ($id) = $sth->fetchrow;
return $id;
}
sub stop($self) { sub stop($self) {
warn "Killing ".$self->command warn "Killing ".$self->command
." , pid: ".$self->pid ." , pid: ".$self->pid
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment