Ignore:
Timestamp:
26 Nov 2012, 23:27:46 (12 years ago)
Author:
uli
Message:

Add VirtualExportJobContainers? for storing export jobs in a central exports container.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/utils/batching.py

    r9718 r9726  
    3232from zope.component import createObject, getUtility
    3333from zope.component.hooks import setSite
    34 from zope.interface import Interface
     34from zope.interface import Interface, implementer
    3535from zope.schema import getFields
    3636from zope.event import notify
     
    3939    IBatchProcessor, FatalCSVError, IObjectConverter, IJobManager,
    4040    ICSVExporter, IGNORE_MARKER, DuplicationError, JOB_STATUS_MAP,
    41     IExportJobContainer, IExportJob)
     41    IExportJobContainer, IExportJob, IExportContainerFinder)
    4242
    4343class BatchProcessor(grok.GlobalUtility):
     
    672672                return entry
    673673        return None
     674
     675class VirtualExportJobContainer(ExportJobContainer):
     676    """A virtual export job container.
     677
     678    Virtual ExportJobContainers can be used as a mixin just like real
     679    ExportJobContainer.
     680
     681    They retrieve and store data in the site-wide ExportJobContainer.
     682
     683    Functionality is currently entirely as for regular
     684    ExportJobContainers, except that data is stored elsewhere.
     685
     686    VirtualExportJobContainers need a registered
     687    IExportContainerFinder utility to find a suitable container for
     688    storing data.
     689    """
     690    grok.implements(IExportJobContainer)
     691
     692    @property
     693    def _site_container(self):
     694        return getUtility(IExportContainerFinder)()
     695
     696    # The following is a simple trick. While ExportJobContainers store
     697    # only one attribute in ZODB, it is sufficient to replace this
     698    # attribute `running_exports` with a suitable manager to make the
     699    # whole virtual container work like the original but with the data
     700    # stored in the site-wide exports container. This way, virtual
     701    # export containers provide the whole functionality of a regular
     702    # exports container but store no data at all with themselves.
     703    @property
     704    def running_exports(self):
     705        """Exports stored in the site-wide exports container.
     706        """
     707        return self._site_container.running_exports
     708
     709    @running_exports.setter
     710    def running_exports(self, value):
     711        self._site_container.running_exports = value
     712
     713    @running_exports.deleter
     714    def running_exports(self):
     715        del self._site_container.running_exports
     716
     717
     718@implementer(IExportContainerFinder)
     719class ExportContainerFinder(grok.GlobalUtility):
     720    """Finder for local (site-wide) export container.
     721    """
     722
     723    def __call__(self):
     724        """Get the local export container-
     725
     726        If no site can be determined or the site provides no export
     727        container, None is returned.
     728        """
     729        site = grok.getSite()
     730        if site is None:
     731            return None
     732        return site.get('datacenter', None)
Note: See TracChangeset for help on using the changeset viewer.