Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Projets publics
Ravada-Mirror
Commits
0b466b33
Commit
0b466b33
authored
Jan 15, 2020
by
Francesc Guasch
Browse files
refactor(frontend): ping backend WS
issue #1196
parent
e57acd59
Changes
2
Hide whitespace changes
Inline
Side-by-side
lib/Ravada/Front.pm
View file @
0b466b33
...
...
@@ -1148,6 +1148,10 @@ sub list_network_interfaces($self, %args) {
return
$interfaces
;
}
sub
_dbh
{
return
$CONNECTOR
->
dbh
;
}
=head2 version
Returns the version of the main module
...
...
lib/Ravada/WebSocket.pm
View file @
0b466b33
...
...
@@ -133,15 +133,54 @@ sub _get_machine_info($rvd, $args) {
return
$info
;
}
sub
_list_recent_requests
($rvd, $seconds) {
my
@now
=
localtime
(
time
-
$seconds
);
$now
[
4
]
++
;
for
(
0
..
4
)
{
$now
[
$_
]
=
"
0
"
.
$now
[
$_
]
if
length
(
$now
[
$_
])
<
2
;
}
my
$time_recent
=
(
$now
[
5
]
+=
1900
)
.
"
-
"
.
$now
[
4
]
.
"
-
"
.
$now
[
3
]
.
"
"
.
$now
[
2
]
.
"
:
"
.
$now
[
1
]
.
"
:
"
.
$now
[
0
];
my
$sth
=
$rvd
->
_dbh
->
prepare
(
"
SELECT id,command, status
"
.
"
FROM requests
"
.
"
WHERE
"
.
"
date_changed >= ?
"
.
"
ORDER BY date_changed
"
);
$sth
->
execute
(
$time_recent
);
my
@reqs
;
while
(
my
$row
=
$sth
->
fetchrow_hashref
)
{
push
@reqs
,(
$row
);
}
return
@reqs
;
}
sub
_ping_backend
($rvd, $args) {
my
$requests
=
$rvd
->
list_requests
(
undef
,
120
);
warn
Dumper
(
$requests
);
my
@requests2
=
grep
{
$_
->
{
status
}
ne
'
requested
'
}
@$requests
;
my
@reqs
=
_list_recent_requests
(
$rvd
,
20
);
my
$requested
=
scalar
(
grep
{
$_
->
{
status
}
eq
'
requested
'
}
@reqs
);
# If there are requests in state different that requested it's ok
return
1
if
scalar
(
@reqs
)
>
$requested
;
my
(
$ping_backend
)
=
grep
{
$_
->
{
command
}
eq
'
ping_backend
'
}
@reqs
;
if
(
!
$ping_backend
)
{
return
0
if
$requested
;
my
@now
=
localtime
(
time
);
my
$seconds
=
$now
[
0
];
warn
$seconds
;
Ravada::
Request
->
ping_backend
()
if
$seconds
<
5
;
return
1
;
}
return
0
if
!
scalar
(
@requests2
)
&&
grep
{
$_
->
{
command
}
eq
'
ping_backend
'}
@$
request
s
;
return
0
if
$ping_backend
->
{
status
}
eq
'
request
ed
'
;
warn
"
***
"
.
Dumper
(
map
{
[
$_
->
{
command
}
=>
$_
->
{
status
}
]
}
@requests2
);
return
scalar
(
@requests2
);
return
1
;
}
sub
_different_list
($list1, $list2) {
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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