Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
biboumi
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
99
Issues
99
List
Boards
Labels
Service Desk
Milestones
Merge Requests
12
Merge Requests
12
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
louiz’
biboumi
Commits
3ea029dd
Commit
3ea029dd
authored
Jun 11, 2014
by
louiz’
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove inactive ad-hoc sessions after a given time
ref
#2521
parent
1604320a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
4 deletions
+24
-4
src/xmpp/adhoc_commands_handler.cpp
src/xmpp/adhoc_commands_handler.cpp
+18
-4
src/xmpp/adhoc_commands_handler.hpp
src/xmpp/adhoc_commands_handler.hpp
+6
-0
No files found.
src/xmpp/adhoc_commands_handler.cpp
View file @
3ea029dd
#include <xmpp/adhoc_commands_handler.hpp>
#include <xmpp/xmpp_component.hpp>
#include <utils/timed_events.hpp>
#include <logger/logger.hpp>
#include <config/config.hpp>
#include <xmpp/jid.hpp>
#include <iostream>
using
namespace
std
::
string_literals
;
AdhocCommandsHandler
::
AdhocCommandsHandler
(
XmppComponent
*
xmpp_component
)
:
xmpp_component
(
xmpp_component
),
commands
{
...
...
@@ -70,10 +73,9 @@ XmlNode&& AdhocCommandsHandler::handle_request(const std::string& executor_jid,
this
->
sessions
.
emplace
(
std
::
piecewise_construct
,
std
::
forward_as_tuple
(
sessionid
,
executor_jid
),
std
::
forward_as_tuple
(
command_it
->
second
,
executor_jid
));
// TODO add a timed event to have an expiration date that deletes
// this session. We could have a nasty client starting commands
// but never finishing the last step, and that would fill the map
// with dummy sessions.
TimedEventsManager
::
instance
().
add_event
(
TimedEvent
(
std
::
chrono
::
steady_clock
::
now
()
+
3600s
,
std
::
bind
(
&
AdhocCommandsHandler
::
remove_session
,
this
,
sessionid
,
executor_jid
),
"adhocsession"
s
+
sessionid
+
executor_jid
));
}
auto
session_it
=
this
->
sessions
.
find
(
std
::
make_pair
(
sessionid
,
executor_jid
));
if
(
session_it
==
this
->
sessions
.
end
())
...
...
@@ -97,6 +99,7 @@ XmlNode&& AdhocCommandsHandler::handle_request(const std::string& executor_jid,
{
this
->
sessions
.
erase
(
session_it
);
command_node
[
"status"
]
=
"completed"
;
TimedEventsManager
::
instance
().
cancel
(
"adhocsession"
s
+
sessionid
+
executor_jid
);
}
else
{
...
...
@@ -115,3 +118,14 @@ XmlNode&& AdhocCommandsHandler::handle_request(const std::string& executor_jid,
log_debug
(
"Number of existing sessions: "
<<
this
->
sessions
.
size
());
return
std
::
move
(
command_node
);
}
void
AdhocCommandsHandler
::
remove_session
(
const
std
::
string
&
session_id
,
const
std
::
string
&
initiator_jid
)
{
auto
session_it
=
this
->
sessions
.
find
(
std
::
make_pair
(
session_id
,
initiator_jid
));
if
(
session_it
!=
this
->
sessions
.
end
())
{
this
->
sessions
.
erase
(
session_it
);
return
;
}
log_error
(
"Tried to remove ad-hoc session for ["
<<
session_id
<<
", "
<<
initiator_jid
<<
"] but none found"
);
}
src/xmpp/adhoc_commands_handler.hpp
View file @
3ea029dd
...
...
@@ -37,6 +37,12 @@ public:
* it as our return value.
*/
XmlNode
&&
handle_request
(
const
std
::
string
&
executor_jid
,
XmlNode
command_node
);
/**
* Remove the session from the list. This is done to avoid filling the
* memory with waiting session (for example due to a client that starts
* multi-steps command but never finishes them).
*/
void
remove_session
(
const
std
::
string
&
session_id
,
const
std
::
string
&
initiator_jid
);
private:
/**
* A pointer to the XmppComponent, to access to basically anything in the
...
...
Write
Preview
Markdown
is supported
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