Author: dmeyer
Date: Tue Jan  9 17:07:02 2007
New Revision: 2371

Modified:
   trunk/beacon/src/server/thumbnailer.py

Log:
Slow down thumbnailing to a minimum of 5 minutes
for crawing files. This is not 100% correct because
it could also slow down other reasons for a
rethumbnailing.


Modified: trunk/beacon/src/server/thumbnailer.py
==============================================================================
--- trunk/beacon/src/server/thumbnailer.py      (original)
+++ trunk/beacon/src/server/thumbnailer.py      Tue Jan  9 17:07:02 2007
@@ -46,6 +46,7 @@
 from kaa.beacon._libthumb import epeg, png, failed
 from videothumb import VideoThumb
 import cpuinfo
+import utils
 
 # get logging object
 log = logging.getLogger('beacon.thumbnail')
@@ -62,6 +63,13 @@
         self.imagefile = imagefile
         self.size = size
         self.priority = priority
+        self._cmdid = imagefile
+
+
+    def __cmp__(self, other):
+        if not isinstance(other, Job):
+            return 1
+        return self._cmdid != other._cmdid
 
 
 class Thumbnailer(object):
@@ -72,11 +80,13 @@
         self.next_client_id = 0
         self.clients = []
         self.jobs = []
+        self._delayed_jobs = {}
         self._timer = kaa.notifier.OneShotTimer(self.step)
         self._ipc = kaa.rpc.Server(os.path.join(tmpdir, 'socket'))
         self._ipc.signals['client_connected'].connect(self.client_connect)
         self._ipc.connect(self)
-
+        # FIXME: hardcoded to making new thumbnails every 5 minutes
+        self._bursthandler = utils.BurstHandler(300, self.activate)
         # video module
         self.videothumb = VideoThumb(self)
 
@@ -119,11 +129,19 @@
     # Internal API
     # -------------------------------------------------------------------------
 
-    def notify_client(self, job):
+    def notify_client(self, job, search=True):
         for id, client in self.clients:
             if id == job.client:
                 client.rpc('finished', job.id, job.filename, job.imagefile)
-                return
+                break
+        if not search:
+            return
+        for j in [ j for j in self.jobs[:] if j == job ]:
+            self.notify_client(j, False)
+            self.jobs.remove(j)
+        for j in [ j for j in self.videothumb.jobs[:] if j == job ]:
+            self.notify_client(j, False)
+            self.videothumb.jobs.remove(j)
 
 
     def create_failed(self, job):
@@ -228,6 +246,21 @@
         self._timer.start(delay)
 
 
+    def activate(self, name):
+        """
+        Activate thumbnail job with given image name.
+        """
+        if not name in self._delayed_jobs:
+            return
+        log.info('schedule delayed thumbnailing for %s', name)
+        for j in self._delayed_jobs.pop(name):
+            # FIXME: it makes no sense to schedule all here just
+            # to remove them on block later on notify_client
+            self.jobs.append(j)
+        # schedule thumbnailer
+        self.schedule_next()
+
+
     # -------------------------------------------------------------------------
     # External RPC API
     # -------------------------------------------------------------------------
@@ -235,7 +268,14 @@
     @kaa.rpc.expose('schedule')
     def schedule(self, id, filename, imagefile, size, priority):
         # FIXME: check if job is already scheduled!!!!
-        self.jobs.append(Job(id, filename, imagefile, size, priority))
+        job = Job(id, filename, imagefile, size, priority)
+        if self._bursthandler.active(imagefile):
+            # schedule called way to often
+            if not imagefile in self._delayed_jobs:
+                self._delayed_jobs[imagefile] = []
+            self._delayed_jobs[imagefile].append(job)
+            return
+        self.jobs.append(job)
         self.schedule_next()
 
 

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to