Commit f5c8c656 authored by Jérome Perrin's avatar Jérome Perrin Committed by Arnaud Fontaine

OOoDocument: explicitly close connections to cloudooo

parent a3b32345
......@@ -27,6 +27,7 @@
#
##############################################################################
import contextlib
import re, zipfile
from io import BytesIO
from warnings import warn
......@@ -178,7 +179,8 @@ class OOoDocument(OOoDocumentExtensibleTraversableMixin, BaseConvertableFileMixi
warn('Your oood version is too old, using old method '
'getAllowedTargets instead of getAllowedTargetList',
DeprecationWarning)
finally:
server_proxy.close()
# tuple order is reversed to be compatible with ERP5 Form
return [(y, x) for x, y in allowed]
......@@ -208,9 +210,9 @@ class OOoDocument(OOoDocumentExtensibleTraversableMixin, BaseConvertableFileMixi
cs.close()
z.close()
return 'text/plain', s
server_proxy = DocumentConversionServerProxy(self)
orig_format = self.getBaseContentType()
generate_result = server_proxy.run_generate(self.getId(),
with contextlib.closing(DocumentConversionServerProxy(self)) as server_proxy:
generate_result = server_proxy.run_generate(self.getId(),
bytes2str(enc(bytes(self.getBaseData()))),
None,
format,
......@@ -382,8 +384,8 @@ class OOoDocument(OOoDocumentExtensibleTraversableMixin, BaseConvertableFileMixi
by invoking the conversion server. Store the result
on the object. Update metadata information.
"""
server_proxy = DocumentConversionServerProxy(self)
response_code, response_dict, response_message = server_proxy.run_convert(
with contextlib.closing(DocumentConversionServerProxy(self)) as server_proxy:
response_code, response_dict, response_message = server_proxy.run_convert(
self.getFilename() or self.getId(),
bytes2str(enc(bytes(self.getData()))),
None,
......@@ -421,8 +423,8 @@ class OOoDocument(OOoDocumentExtensibleTraversableMixin, BaseConvertableFileMixi
# XXX please pass a meaningful description of error as argument
raise NotConvertedError()
server_proxy = DocumentConversionServerProxy(self)
response_code, response_dict, response_message = \
with contextlib.closing(DocumentConversionServerProxy(self)) as server_proxy:
response_code, response_dict, response_message = \
server_proxy.run_setmetadata(self.getId(),
bytes2str(enc(bytes(self.getBaseData()))),
kw)
......
......@@ -27,8 +27,9 @@
#
##############################################################################
import logging
import re
from zLOG import LOG, WARNING
from zLOG import LOG
from AccessControl import ClassSecurityInfo
from Acquisition import aq_base
from Products.ERP5Type.Accessor.Constant import PropertyGetter as ConstantGetter
......@@ -102,6 +103,7 @@ class DocumentConversionServerProxy():
"""
def __init__(self, context):
self._serverproxy_list = []
self._logger = logging.getLogger(__name__)
preference_tool = getToolByName(context, 'portal_preferences')
self._ooo_server_retry = (
preference_tool.getPreferredDocumentConversionServerRetry() or
......@@ -113,9 +115,9 @@ class DocumentConversionServerProxy():
if not (address and port):
raise ConversionError('OOoDocument: cannot proceed with conversion:'
' conversion server url is not defined in preferences')
LOG('Document', WARNING, 'PreferredOoodocServer{Address,PortNumber}' + \
' are DEPRECATED please use PreferredDocumentServerUrl instead', error=True)
self._logger.warning(
'PreferredOoodocServer{Address,PortNumber} are DEPRECATED '
'please use PreferredDocumentServerUrl instead')
uri_list = ['%s://%s:%s' % ('http', address, port)]
......@@ -209,6 +211,18 @@ class DocumentConversionServerProxy():
def __getattr__(self, attr):
return partial(self._proxy_function, attr)
def close(self):
error_list = []
for server_addr, proxy in self._serverproxy_list:
try:
proxy.__call__('close')()
except Exception as e:
self._logger.exception('Error closing %s', server_addr)
error_list.append(e)
for e in error_list:
raise e
from erp5.component.mixin.DocumentExtensibleTraversableMixin import DocumentExtensibleTraversableMixin
from erp5.component.interface.IConvertable import IConvertable
from erp5.component.interface.ITextConvertable import ITextConvertable
......
Markdown is supported
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