Skip to content

Commit

Permalink
Merge remote-tracking branch 'collective/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
EEA Jenkins committed May 22, 2017
2 parents b0bf101 + 69829ef commit 97473e5
Show file tree
Hide file tree
Showing 12 changed files with 92 additions and 25 deletions.
9 changes: 8 additions & 1 deletion docs/HISTORY.txt
@@ -1,8 +1,15 @@
Changelog
=========

9.7.dev0 - (unreleased)
9.8.dev0 - (unreleased)
-----------------------
* Change: Add dedicated async quota for relations jobs
[avoinea refs #84915]
* Change: fixed PyLint warnings and errors
[valipod refs #84949]

9.7 - (2017-05-15)
------------------
* Change: fixed PyLint warnings and errors
[eduard-fironda refs #84949]

Expand Down
13 changes: 13 additions & 0 deletions eea/relations/async/__init__.py
@@ -0,0 +1,13 @@
""" Async
"""
from zope.interface import Interface

try:
from plone.app.async.interfaces import IAsyncService
except ImportError:
class IAsyncService(Interface):
""" No async """

__all__ = [
IAsyncService.__name__,
]
13 changes: 13 additions & 0 deletions eea/relations/async/configure.zcml
@@ -0,0 +1,13 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:zcml="http://namespaces.zope.org/zcml"
i18n_domain="eea">

<configure zcml:condition="installed plone.app.async">
<subscriber
for="plone.app.async.interfaces.IQueueReady"
handler=".subscribers.configureQueue"
/>
</configure>

</configure>
35 changes: 35 additions & 0 deletions eea/relations/async/subscribers.py
@@ -0,0 +1,35 @@
""" Subscribers
"""
import os
import logging
from plone.app.async.subscribers import set_quota
logger = logging.getLogger('eea.relations')


def getMaximumThreads(queue):
""" Get the maximum threads per queue
"""
size = 0
for da in queue.dispatchers.values():
if not da.activated:
continue
for _agent in da.values():
size += 3
return size or 1


def configureQueue(event):
""" Configure zc.async queue for rdf async jobs
"""
queue = event.object

try:
size = int(os.environ.get(
'EEARELATIONS_ASYNC_THREADS', getMaximumThreads(queue)))
except Exception, err:
logger.exception(err)
size = 1

set_quota(queue, 'relations', size=size)
logger.info("quota 'relations' with size %r configured in queue %r.",
size, queue.name)
8 changes: 0 additions & 8 deletions eea/relations/config.py
Expand Up @@ -2,14 +2,6 @@
"""
from eea.relations import graph
from zope.i18nmessageid import MessageFactory
from zope.interface import Interface
try:
from plone.app.async import interfaces
IAsyncService = interfaces.IAsyncService
except (ImportError, AttributeError):
class IAsyncService(Interface):
""" Fallback async service
"""

EEAMessageFactory = MessageFactory('eea')
GRAPHVIZ_PATHS = graph.GRAPHVIZ_PATHS
Expand Down
1 change: 1 addition & 0 deletions eea/relations/configure.zcml
Expand Up @@ -8,6 +8,7 @@
<include file="profiles.zcml" />
<include file="skins.zcml" />

<include package=".async" />
<include package=".browser" />
<include package=".subtypes" />
<include package=".vocabulary" />
Expand Down
3 changes: 2 additions & 1 deletion eea/relations/discover/browser.py
Expand Up @@ -8,6 +8,7 @@
from eea.relations.discover.interfaces import IBrowserView
from AccessControl import Unauthorized


class View(BrowserView):
""" Display auto discovered relations
"""
Expand All @@ -33,7 +34,7 @@ def generatorTabs(self, tupleResult):
"""
for tab, brains in tupleResult:
brains = [b for b in self.checkPermission(brains)]
if not len(brains):
if not brains:
continue
yield tab, brains

Expand Down
5 changes: 3 additions & 2 deletions eea/relations/exportimport/relation.py
Expand Up @@ -4,6 +4,7 @@
from eea.relations.content.relation import RelationSchema
from Products.GenericSetup.utils import XMLAdapterBase


class RelationXMLAdapter(XMLAdapterBase):
""" Generic setup import/export xml adapter
"""
Expand Down Expand Up @@ -51,11 +52,11 @@ def _importNode(self, node):
continue
elements.append(element.getAttribute('value'))
if elements:
value = (not purge) and elements or []
value = elements if not purge else []
else:
value = self._getNodeText(child)
value = value.decode('utf-8')
value = (not purge) and value or u''
value = value if not purge else u''

if name in ('required',):
value = self._convertToBoolean(value)
Expand Down
2 changes: 1 addition & 1 deletion eea/relations/rules/interfaces.py
Expand Up @@ -2,7 +2,7 @@
"""
from zope import schema
from zope.interface import Interface
from eea.relations.config import IAsyncService
from eea.relations.async import IAsyncService
from eea.relations.config import EEAMessageFactory as _
from plone.stringinterp.interfaces import IContextWrapper

Expand Down
24 changes: 14 additions & 10 deletions eea/relations/rules/relateditems.py
Expand Up @@ -14,7 +14,7 @@
from plone.contentrules.rule.interfaces import IExecutable, IRuleElementData

from eea.relations.config import EEAMessageFactory as _
from eea.relations.config import IAsyncService
from eea.relations.async import IAsyncService
from eea.relations.rules.interfaces import IRelatedItemsAction
from eea.relations.rules.async import forward_transition_change
from eea.relations.rules.async import backward_transition_change
Expand Down Expand Up @@ -45,15 +45,17 @@ def forward(self):
self.element.transition,
portal_url
)
async = queryUtility(IAsyncService)
async_service = queryUtility(IAsyncService)
try:
async.queueJob(
async_queue = async_service.getQueues()['']
async_service.queueJobInQueue(
async_queue, ('relations',),
forward_transition_change,
self.event.object,
self.element.transition,
portal_url
)
except ComponentLookupError:
except (AttributeError, ComponentLookupError):
return forward_transition_change(
self.event.object,
self.element.transition,
Expand All @@ -72,15 +74,17 @@ def backward(self):
self.element.transition,
portal_url
)
async = queryUtility(IAsyncService)
async_service = queryUtility(IAsyncService)
try:
async.queueJob(
async_queue = async_service.getQueues()['']
async_service.queueJobInQueue(
async_queue, ('relations',),
backward_transition_change,
self.event.object,
self.element.transition,
portal_url
)
except ComponentLookupError:
except (AttributeError, ComponentLookupError):
return backward_transition_change(
self.event.object,
self.element.transition,
Expand Down Expand Up @@ -108,9 +112,9 @@ def summary(self):
""" Need to access the content rule with the related items action.
"""
return _(
u"Execute transition ${transition}",
mapping=dict(transition=self.transition)
)
u"Execute transition ${transition}",
mapping=dict(transition=self.transition)
)


class RelatedItemsAddForm(AddForm):
Expand Down
2 changes: 1 addition & 1 deletion eea/relations/upgrades/evolve80.py
Expand Up @@ -40,7 +40,7 @@ def fix_eea_refs(context):
logger.warn("'WARNING: Sparql with problems: %s",
brain.getPath())
if should_fix_eea_refs:
if not len(obj.eea_refs):
if not obj.eea_refs:
continue
there_are_fixes = False
fixed_refs = []
Expand Down
2 changes: 1 addition & 1 deletion eea/relations/version.txt
@@ -1 +1 @@
9.7.dev0
9.8.dev0

0 comments on commit 97473e5

Please sign in to comment.