maposmatic-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Maposmatic-dev] [PATCH maposmatic 5/9] Merge the StandaloneMapOSMaticDa


From: Maxime Petazzoni
Subject: [Maposmatic-dev] [PATCH maposmatic 5/9] Merge the StandaloneMapOSMaticDaemon into the base MapOSMaticDaemon class
Date: Sun, 24 Jan 2010 14:43:19 +0100

---
 scripts/daemon.py |   37 +++++++++++++++++--------------------
 1 files changed, 17 insertions(+), 20 deletions(-)

diff --git a/scripts/daemon.py b/scripts/daemon.py
index cfaab93..bddc7ff 100755
--- a/scripts/daemon.py
+++ b/scripts/daemon.py
@@ -40,8 +40,9 @@ RESULT_CANCELED    = 'rendering took too long, canceled'
 
 class MapOSMaticDaemon:
     """
-    This is a no-op rendering daemon, base class for the different
-    implementations of rendering scheduling.
+    This is a basic rendering daemon, base class for the different
+    implementations of rendering scheduling. By default, it acts as a
+    standalone, single-process MapOSMatic rendering daemon.
     """
 
     def __init__(self, frequency):
@@ -73,25 +74,19 @@ class MapOSMaticDaemon:
         LOG.info("MapOSMatic rendering daemon terminating.")
 
     def dispatch(self, job):
-        raise NotImplementedError
+        """Dispatch the given job. In this simple single-process daemon, this
+        is as simple as rendering it."""
+        self.render(job)
 
     def render(self, job):
-        raise NotImplementedError
+        """Render the given job, handling the different rendering outcomes
+        (success or failures)."""
 
-class StandaloneMapOSMaticDaemon(MapOSMaticDaemon):
-    """
-    A simple, serial, single-process standalone MapOSMatic rendering daemon.
-    """
-
-    def __init__(self, frequency):
-        MapOSMaticDaemon.__init__(self, frequency)
-
-    def dispatch(self, job):
         LOG.info("Rendering job #%d '%s'..." %
                  (job.id, job.maptitle))
         job.start_rendering()
 
-        ret = self.render(job)
+        ret = render.render_job(job)
         if ret == 0:
             msg = RESULT_SUCCESSFULL
             LOG.info("Finished rendering of job #%d." % job.id)
@@ -105,15 +100,17 @@ class StandaloneMapOSMaticDaemon(MapOSMaticDaemon):
 
         job.end_rendering(msg)
 
-    def render(self, job):
-        return render.render_job(job)
-
-class ForkingMapOSMaticDaemon(MapOSMaticDaemon):
+class SubprocessMapOSMaticDaemon(MapOSMaticDaemon):
     """
-    A forking, subprocess-based implementation of the MapOSMatic rendering
+    A spawning, subprocess-based implementation of the MapOSMatic rendering
     daemon. Each job is handled by a subprocess from render.py.
     """
 
+    def __init__(self, frequency, max_process=4):
+        MapOSMaticDaemon.__init__(self, frequency)
+        self.max_process = max_process
+        self.n_process = 0
+
     def dispatch(self, job):
         LOG.info("Forking to render job #%d '%s'..." %
                  (job.id, job.maptitle))
@@ -240,7 +237,7 @@ if __name__ == '__main__':
                   "Please use a valid RENDERING_RESULT_PATH.")
         sys.exit(1)
 
-    daemon = StandaloneMapOSMaticDaemon(10)
+    daemon = MapOSMaticDaemon(10)
     cleaner = RenderingsGarbageCollector(20)
 
     cleaner.start()
-- 
1.6.3.3.277.g88938c





reply via email to

[Prev in Thread] Current Thread [Next in Thread]