Skip to content

Commit

Permalink
UI for queue control
Browse files Browse the repository at this point in the history
  • Loading branch information
zopyx committed Aug 19, 2007
1 parent f4c1f3b commit f25f30c
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
36 changes: 34 additions & 2 deletions MailHost.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -196,7 +197,8 @@ def _stopQueueProcessorThread(self):
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 """
Expand All @@ -208,6 +210,36 @@ def _startQueueProcessorThread(self):
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')
Expand Down
25 changes: 25 additions & 0 deletions dtml/manageMailHost.dtml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>

Expand Down

0 comments on commit f25f30c

Please sign in to comment.