Commit ec2c6d5e authored by Andreas Jung's avatar Andreas Jung

UI for queue control

parent 092dee5d
...@@ -24,7 +24,7 @@ from cStringIO import StringIO ...@@ -24,7 +24,7 @@ from cStringIO import StringIO
import Acquisition import Acquisition
import OFS.SimpleItem import OFS.SimpleItem
from AccessControl import ClassSecurityInfo 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 use_mailhost_services
from AccessControl.Permissions import view_management_screens from AccessControl.Permissions import view_management_screens
from AccessControl.Role import RoleManager from AccessControl.Role import RoleManager
...@@ -33,6 +33,7 @@ from DateTime import DateTime ...@@ -33,6 +33,7 @@ from DateTime import DateTime
from zope.interface import implements from zope.interface import implements
from zope.sendmail.mailer import SMTPMailer from zope.sendmail.mailer import SMTPMailer
from zope.sendmail.maildir import Maildir
from zope.sendmail.delivery import DirectMailDelivery, QueuedMailDelivery, \ from zope.sendmail.delivery import DirectMailDelivery, QueuedMailDelivery, \
QueueProcessorThread QueueProcessorThread
...@@ -196,7 +197,8 @@ class MailBase(Acquisition.Implicit, OFS.SimpleItem.Item, RoleManager): ...@@ -196,7 +197,8 @@ class MailBase(Acquisition.Implicit, OFS.SimpleItem.Item, RoleManager):
while thread.isAlive(): while thread.isAlive():
# wait until thread is really dead # wait until thread is really dead
time.sleep(0.1) time.sleep(0.1)
del queue_threads[path]
LOG.info('Thread for %s stopped' % path)
def _startQueueProcessorThread(self): def _startQueueProcessorThread(self):
""" Start thread for processing the mail queue """ """ Start thread for processing the mail queue """
...@@ -208,6 +210,36 @@ class MailBase(Acquisition.Implicit, OFS.SimpleItem.Item, RoleManager): ...@@ -208,6 +210,36 @@ class MailBase(Acquisition.Implicit, OFS.SimpleItem.Item, RoleManager):
thread.setQueuePath(self.smtp_queue_directory) thread.setQueuePath(self.smtp_queue_directory)
thread.start() thread.start()
queue_threads[path] = thread 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') security.declarePrivate('_send')
......
...@@ -58,6 +58,7 @@ ...@@ -58,6 +58,7 @@
<input type="text" name="smtp_uid" size="15" <input type="text" name="smtp_uid" size="15"
value="&dtml-smtp_uid;"/> value="&dtml-smtp_uid;"/>
</td> </td>
<dtml-var "smtp_uid" >
<td> <td>
<span class="form-help">(optional for SMTP AUTH)</span> <span class="form-help">(optional for SMTP AUTH)</span>
</td> </td>
...@@ -114,6 +115,30 @@ ...@@ -114,6 +115,30 @@
</div> </div>
</td> </td>
</tr> </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> </table>
</form> </form>
......
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