Ignore:
Timestamp:
9 Aug 2012, 08:58:14 (12 years ago)
Author:
uli
Message:

Add interfaces/constants for asynchronous jobs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/branches/uli-zc-async/src/waeup/kofa/interfaces.py

    r9003 r9097  
    1919import re
    2020import codecs
     21import zc.async.interfaces
    2122import zope.i18nmessageid
    2223from datetime import datetime
     
    2930from zope.component import getUtility
    3031from zope.component.interfaces import IObjectEvent
    31 from zope.container.interfaces import INameChooser
     32from zope.configuration.fields import Path
     33from zope.container.interfaces import INameChooser, IContainer
    3234from zope.interface import Interface, Attribute
    3335from zope.schema.interfaces import IObject
     
    3941DELETION_MARKER = 'XXX'
    4042IGNORE_MARKER = '<IGNORE>'
     43WAEUP_KEY = 'waeup.kofa'
     44VIRT_JOBS_CONTAINER_NAME = 'jobs'
    4145
    4246CREATED = 'created'
     
    4953REGISTERED = 'courses registered'
    5054VALIDATED = 'courses validated'
     55
     56#: A dict giving job status as tuple (<STRING>, <TRANSLATED_STRING>),
     57#: the latter for UI purposes.
     58JOB_STATUS_MAP = {
     59    zc.async.interfaces.NEW: ('new', _('new')),
     60    zc.async.interfaces.COMPLETED: ('completed', _('completed')),
     61    zc.async.interfaces.PENDING: ('pending', _('pending')),
     62    zc.async.interfaces.ACTIVE: ('active', _('active')),
     63    zc.async.interfaces.ASSIGNED: ('assigned', _('assigned')),
     64    zc.async.interfaces.CALLBACKS: ('callbacks', _('callbacks')),
     65    }
    5166
    5267#default_rest_frontpage = u'' + codecs.open(os.path.join(
     
    10811096        """
    10821097
    1083 from zope.configuration.fields import Path
     1098
    10841099class IDataCenterConfig(Interface):
    10851100    path = Path(
     
    10901105        )
    10911106
     1107#
     1108# Asynchronous job handling and related
     1109#
     1110class IJobManager(IKofaObject):
     1111    """A manager for asynchronous running jobs (tasks).
     1112    """
     1113    def put(job, site=None):
     1114        """Put a job into task queue.
     1115
     1116        If no `site` is given, queue job in context of current local
     1117        site.
     1118
     1119        Returns a job_id to identify the put job. This job_id is
     1120        needed for further references to the job.
     1121        """
     1122
     1123    def jobs(site=None):
     1124        """Get an iterable of jobs stored.
     1125        """
     1126
     1127    def get(job_id, site=None):
     1128        """Get the job with id `job_id`.
     1129
     1130        For the `site` parameter see :meth:`put`.
     1131        """
     1132
     1133    def remove(job_id, site=None):
     1134        """Remove job with `job_id` from stored jobs.
     1135        """
     1136
     1137    def start_test_job(site=None):
     1138        """Start a test job.
     1139        """
     1140
     1141class IProgressable(Interface):
     1142    """A component that can indicate its progress status.
     1143    """
     1144    percent = schema.Float(
     1145        title = u'Percent of job done already.',
     1146        )
     1147
     1148class IJobContainer(IContainer):
     1149    """A job container contains IJob objects.
     1150    """
     1151
     1152class IExportJob(zc.async.interfaces.IJob):
     1153    def __init__(site, exporter_name):
     1154        pass
     1155
     1156class IExportJobContainer(Interface):
     1157    """A component that contains (maybe virtually) export jobs.
     1158    """
     1159    def start_export_job(exporter_name, user_id):
     1160        """Start asynchronous export job.
     1161
     1162        `exporter_name` is the name of an exporter utility to be used.
     1163
     1164        `user_id` is the ID of the user that triggers the export.
     1165
     1166        The job_id is stored along with exporter name and user id in a
     1167        persistent list.
     1168
     1169        Returns the job ID of the job started.
     1170        """
     1171
     1172    def get_running_export_jobs(user_id=None):
     1173        """Get export jobs for user with `user_id` as list of tuples.
     1174
     1175        Each tuples holds ``<job_id>, <exporter_name>, <user_id>`` in
     1176        that order. The ``<exporter_name>`` is the utility name of the
     1177        used exporter.
     1178
     1179        If `user_id` is ``None``, all running jobs are returned.
     1180        """
     1181
     1182    def get_export_jobs_status(user_id=None):
     1183        """Get running/completed export jobs for `user_id` as list of tuples.
     1184
     1185        Each tuple holds ``<raw status>, <status translated>,
     1186        <exporter title>`` in that order, where ``<status
     1187        translated>`` and ``<exporter title>`` are translated strings
     1188        representing the status of the job and the human readable
     1189        title of the exporter used.
     1190        """
     1191
     1192    def delete_export_entry(entry):
     1193        """Delete the export denoted by `entry`.
     1194
     1195        Removes `entry` from the local `running_exports` list and also
     1196        removes the regarding job via the local job manager.
     1197
     1198        `entry` is a tuple ``(<job id>, <exporter name>, <user id>)``
     1199        as created by :meth:`start_export_job` or returned by
     1200        :meth:`get_running_export_jobs`.
     1201        """
Note: See TracChangeset for help on using the changeset viewer.