[Erp5-report] r11927 - in /erp5/trunk/products/TimerService: ./ timerserver/

nobody at svn.erp5.org nobody at svn.erp5.org
Mon Jan 8 15:29:46 CET 2007


Author: kevin
Date: Mon Jan  8 15:29:44 2007
New Revision: 11927

URL: http://svn.erp5.org?rev=11927&view=rev
Log:
First Klaus' patch to make zope start nicer

Modified:
    erp5/trunk/products/TimerService/TimerService.py
    erp5/trunk/products/TimerService/timerserver/TimerServer.py

Modified: erp5/trunk/products/TimerService/TimerService.py
URL: http://svn.erp5.org/erp5/trunk/products/TimerService/TimerService.py?rev=11927&r1=11926&r2=11927&view=diff
==============================================================================
--- erp5/trunk/products/TimerService/TimerService.py (original)
+++ erp5/trunk/products/TimerService/TimerService.py Mon Jan  8 15:29:44 2007
@@ -53,15 +53,16 @@
                          for path in self._subscribers]
 
         tick = time.time()
-        prev_tick = tick - interval
-        next_tick = tick + interval
+#        prev_tick = tick - interval
+#        next_tick = tick + interval
 
-        LOG('TimerService', INFO, 'Ttimer tick at %s\n'%time.ctime(tick))
+#        LOG('TimerService', INFO, 'Ttimer tick at %s\n'%time.ctime(tick))
 
         for subscriber in subscriptions:
             try:
-                subscriber.process_timer(
-                    interval, DateTime(tick), DateTime(prev_tick), DateTime(next_tick))
+#                subscriber.process_timer(
+#                    interval, DateTime(tick), DateTime(prev_tick), DateTime(next_tick))
+              subscriber.process_timer(tick, interval)
             except:
                 LOG('TimerService', ERROR, 'Process timer error', error = sys.exc_info())
 
@@ -75,6 +76,12 @@
         subscribers = self._subscribers
         if path not in subscribers:
             subscribers.append(path)
+            self._subscribers = subscribers
+
+    def unsubscribeByPath(self, path):
+        subscribers = self._subscribers
+        if path in subscribers:
+            subscribers.remove(path)
             self._subscribers = subscribers
 
     def unsubscribe(self, ob):
@@ -94,12 +101,14 @@
 
     def manage_removeSubscriptions(self, no, REQUEST=None):
         """ """
-        subs = self.listAllSubscriptions()
+        subs = self.lisSubscriptions()
+
+        #LOG('asdd',INFO,subs)
 
         remove_list = [subs[n] for n in [int(n) for n in no]]
 
-        for subs, event, fl in remove_list:
-            self.unsubscribe( subs, event_type=event )
+        for sub in remove_list:
+            self.unsubscribeByPath(sub)
 
         if REQUEST is not None:
             REQUEST.RESPONSE.redirect('manage_viewSubscriptions')

Modified: erp5/trunk/products/TimerService/timerserver/TimerServer.py
URL: http://svn.erp5.org/erp5/trunk/products/TimerService/timerserver/TimerServer.py?rev=11927&r1=11926&r2=11927&view=diff
==============================================================================
--- erp5/trunk/products/TimerService/timerserver/TimerServer.py (original)
+++ erp5/trunk/products/TimerService/timerserver/TimerServer.py Mon Jan  8 15:29:44 2007
@@ -6,7 +6,10 @@
 import traceback
 
 import thread
-import sys, os, errno, time
+
+import sys, os, errno, time, socket
+
+import ZPublisher.Client
 from StringIO import StringIO
 from zLOG import LOG, INFO
 
@@ -14,9 +17,10 @@
 from ZPublisher.BaseRequest import BaseRequest
 from ZPublisher.BaseResponse import BaseResponse
 from ZPublisher.HTTPRequest import HTTPRequest
+from ZPublisher import Client
 
 class TimerServer:
-    def __init__(self, module, interval=600):
+    def __init__(self, module, interval=5):
         self.module = module
 
         self.interval = interval
@@ -35,6 +39,34 @@
             '\tInterval: %s seconds.\n'%(time.ctime(time.time()), interval))
 
     def run(self):
+
+        # wait until the zhttp_server exist in socket_map
+        # because TimerService has to be started after the Zope HTTPServer
+        from asyncore import socket_map
+        while 1:
+            time.sleep(5)
+            for k, v in socket_map.items():
+                if hasattr(v, 'port'):
+                        # see Zope/lib/python/App/ApplicationManager.py: def getServers(self)
+                        type = str(getattr(v, '__class__', 'unknown'))
+                        if type == 'ZServer.HTTPServer.zhttp_server':
+                            port = v.port
+                            break
+            if port:
+                break
+
+        ip = socket.gethostbyname(socket.gethostname())
+
+        # To be very sure, try to connect to the HTTPServer
+        # and only start after we are able to connect
+        while 1:
+            time.sleep(5)
+            try:
+                Client.call('http://%s:%s' %(ip, port))
+            except ValueError:
+                continue
+            break
+
         module = self.module
         interval = self.interval
 




More information about the Erp5-report mailing list