From ff9b80ad9ca0741c78a5ca3cfe163ee6dea3d5ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tadej=20Borov=C5=A1ak?= Date: Thu, 6 Sep 2018 14:31:02 +0200 Subject: [PATCH] Allow ems to terminate connection after use This commit adds a simple disconnect hook that allows ext management systems (providers) to terminate connection after it is no longer needed. Use case for such functionality is provider that needs to delete user session after the operation since user sessions are long-lived and number of concurrent live sessions is limited. --- app/models/ext_management_system.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/models/ext_management_system.rb b/app/models/ext_management_system.rb index f7c2322a32d7..ea48a457bae3 100644 --- a/app/models/ext_management_system.rb +++ b/app/models/ext_management_system.rb @@ -402,7 +402,13 @@ def emstype_description def with_provider_connection(options = {}) raise _("no block given") unless block_given? _log.info("Connecting through #{self.class.name}: [#{name}]") - yield connect(options) + connection = connect(options) + yield connection + ensure + disconnect(connection) if connection + end + + def disconnect(_connection) end def self.refresh_all_ems_timer