[Checkins] SVN: Zope/trunk/lib/python/Products/MailHost/ UI for queue control

Andreas Jung andreas at andreas-jung.com
Sun Aug 19 07:32:54 EDT 2007


Log message for revision 78988:
  UI for queue control
  

Changed:
  U   Zope/trunk/lib/python/Products/MailHost/MailHost.py
  U   Zope/trunk/lib/python/Products/MailHost/dtml/manageMailHost.dtml

-=-
Modified: Zope/trunk/lib/python/Products/MailHost/MailHost.py
===================================================================
--- Zope/trunk/lib/python/Products/MailHost/MailHost.py	2007-08-19 09:54:04 UTC (rev 78987)
+++ Zope/trunk/lib/python/Products/MailHost/MailHost.py	2007-08-19 11:32:53 UTC (rev 78988)
@@ -24,7 +24,7 @@
 import Acquisition
 import OFS.SimpleItem
 from AccessControl import ClassSecurityInfo
-from AccessControl.Permissions import change_configuration
+from AccessControl.Permissions import change_configuration, view
 from AccessControl.Permissions import use_mailhost_services
 from AccessControl.Permissions import view_management_screens
 from AccessControl.Role import RoleManager
@@ -33,6 +33,7 @@
 
 from zope.interface import implements
 from zope.sendmail.mailer import SMTPMailer
+from zope.sendmail.maildir import Maildir
 from zope.sendmail.delivery import DirectMailDelivery, QueuedMailDelivery, \
                             QueueProcessorThread
 
@@ -196,8 +197,9 @@
             while thread.isAlive():
                 # wait until thread is really dead
                 time.sleep(0.1)
+            del queue_threads[path]
+            LOG.info('Thread for %s stopped' % path)
 
-
     def _startQueueProcessorThread(self):
         """ Start thread for processing the mail queue """
         
@@ -208,8 +210,38 @@
             thread.setQueuePath(self.smtp_queue_directory)
             thread.start()
             queue_threads[path] = thread     
+            LOG.info('Thread for %s started' % path)
 
+     
+    security.declareProtected(view, 'queueLength')
+    def queueLength(self):
+        """ return length of mail queue """
 
+        maildir = Maildir(self.smtp_queue_directory)
+        return len([item for item in maildir])
+
+
+    security.declareProtected(view, 'queueThreadAlive')
+    def queueThreadAlive(self):
+        """ return True/False is queue thread is working """
+
+        th = queue_threads.get(self.absolute_url(1))
+        if th:
+            return th.isAlive()
+        return False
+
+    security.declareProtected(change_configuration, 'manage_restartQueueThread')
+    def manage_restartQueueThread(self, REQUEST=None):
+        """ Restart the queue processor thread """
+
+        self._stopQueueProcessorThread()
+        self._startQueueProcessorThread()
+
+        if REQUEST is not None:
+            msg = 'Queue processor thread restarted'
+            return self.manage_main(self, REQUEST, manage_tabs_message=msg)
+
+
     security.declarePrivate('_send')
     def _send(self, mfrom, mto, messageText):
         """ Send the message """

Modified: Zope/trunk/lib/python/Products/MailHost/dtml/manageMailHost.dtml
===================================================================
--- Zope/trunk/lib/python/Products/MailHost/dtml/manageMailHost.dtml	2007-08-19 09:54:04 UTC (rev 78987)
+++ Zope/trunk/lib/python/Products/MailHost/dtml/manageMailHost.dtml	2007-08-19 11:32:53 UTC (rev 78988)
@@ -58,6 +58,7 @@
     <input type="text" name="smtp_uid" size="15"
      value="&dtml-smtp_uid;"/>
     </td>
+<dtml-var "smtp_uid" >
     <td>
     <span class="form-help">(optional for SMTP AUTH)</span>
     </td>
@@ -114,6 +115,30 @@
     </div>
     </td>
   </tr>
+  <tr>
+    <td align="left" valign="top">
+    <div class="form-label">
+    Mails in queue <br/> 
+    </div>
+    </td>
+    <td align="left" valign="top">
+        <span class="form-help"><dtml-var queueLength></span>
+    </td>
+  </tr>
+  <tr>
+    <td align="left" valign="top">
+    <div class="form-label">
+    Queue processor thread alive?<br/> 
+    </div>
+    </td>
+    <td align="left" valign="top">
+        <div class="form-help">
+            <dtml-var queueThreadAlive>
+            <br/>
+            <a href="manage_restartQueueThread">Restart queue processor thread</a> (this may take some seconds)
+        </div>
+    </td>
+  </tr>
 </table>
 </form>
 



More information about the Checkins mailing list