Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Projets publics
Ravada-Mirror
Commits
b7db4bdd
Commit
b7db4bdd
authored
Sep 14, 2018
by
Francesc Guasch
Browse files
wip(requests): do not repeat cleanup requests
issue #838
parent
b2fd93da
Changes
1
Hide whitespace changes
Inline
Side-by-side
lib/Ravada/Request.pm
View file @
b7db4bdd
...
...
@@ -106,7 +106,7 @@ our %COMMAND = (
}
,
priority
=>
{
limit
=>
20
,
commands
=>
['
clone
','
start
']
,
commands
=>
['
clone
','
start
'
,'
cleanup
'
]
}
);
lock_hash
%COMMAND
;
...
...
@@ -1049,6 +1049,7 @@ sub refresh_vms {
my
$class
=
ref
(
$proto
)
||
$proto
;
my
$args
=
_check_args
('
refresh_vms
',
@
_
);
return
if
_requested
('
refresh_vms
');
my
$self
=
{};
bless
(
$self
,
$class
);
...
...
@@ -1110,6 +1111,8 @@ sub cleanup($proto , @args) {
my
$args
=
_check_args
('
cleanup
',
@args
);
return
if
_requested
('
cleanup
');
my
$self
=
{};
bless
(
$self
,
$class
);
...
...
@@ -1322,6 +1325,7 @@ sub enforce_limits {
my
$args
=
_check_args
('
enforce_limits
',
@
_
);
return
if
_requested
('
enforce_limits
');
$args
->
{
timeout
}
=
$TIMEOUT_SHUTDOWN
if
!
exists
$args
->
{
timeout
};
my
$self
=
{};
...
...
@@ -1352,8 +1356,12 @@ This method is used for commands that take long to run as garbage collection.
=cut
sub
done_recently
{
my
(
$self
,
$seconds
)
=
@_
;
sub
done_recently
($self, $seconds=60,$command=undef) {
my
$id_req
=
0
;
if
(
$self
)
{
$id_req
=
$self
->
id
;
$command
=
$self
->
command
;
}
my
$sth
=
$$CONNECTOR
->
dbh
->
prepare
(
"
SELECT id FROM requests
"
.
"
WHERE date_changed > ?
"
...
...
@@ -1363,11 +1371,24 @@ sub done_recently {
.
"
AND id <> ?
"
);
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
;
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) {
warn
"
Killing
"
.
$self
->
command
.
"
, pid:
"
.
$self
->
pid
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment