def schedule_next(self, fast=False): """ Schedule next thumbnail based on priority. """ if self._timer.active or not self.jobs: return if fast: # We already waited the last delay, but didn't end up consuming # CPU, so consider our debt paid. delay = 0 else: delay = scheduler.next(config.scheduler.policy) * config.scheduler.multiplier if self.jobs[0].priority: # Thumbnail is high priority, use less of a delay. delay /= 10.0 self._timer.start(delay)
def schedule_next(self, fast=False): """ Schedule next thumbnail based on priority. """ if self._timer.active or not self.jobs: return if fast: # We already waited the last delay, but didn't end up consuming # CPU, so consider our debt paid. delay = 0 else: delay = scheduler.next( config.scheduler.policy) * config.scheduler.multiplier if self.jobs[0].priority: # Thumbnail is high priority, use less of a delay. delay /= 10.0 self._timer.start(delay)
def _thumbnailer(self): while self.jobs and not kaa.main.is_stopped(): job = self.jobs.pop(0) log.info('Now processing video thumbnail job: file=%s, qlen=%d', job.filename, len(self.jobs)) for size in ('large', 'normal'): imagefile = job.imagefile % size if not os.path.isfile(imagefile): # One (or both) of the large and normal thumbnails don't exist, so # we must generate. break metadata = kaa.metadata.parse(imagefile) mtime = metadata.get('Thumb::MTime') if mtime != str(os.stat(job.filename)[stat.ST_MTIME]): # File mtime doesn't match the stored mtime in the thumbnail metadata, # so must regenerate. break else: # No thumb generation needed. continue # XXX: this isn't very effective because we can't throttle mplayer # once it's running. We run mplayer at the lowest possible priority # (if schedtool is available), so that'll have to suffice. # IDEA: actually we can throttle mplayer, if we remove -benchmark and pass -fps. delay = scheduler.next(self.config.scheduler.policy) * self.config.scheduler.multiplier if delay: # too much CPU load, slow down yield kaa.delay(delay) try: success = yield self._generate(job) except Exception: success = False if not success: # Something went awry, generate a failed thumbnail file. self.create_failed(job) # Notify client via rpc that this thumbnail job is done. self.notify_client(job)