コード例 #1
0
 def wait(self, timeout=None, initial_delay=0.005,
          max_delay=1.0, sleep_func=time.sleep):
     if initial_delay > max_delay:
         raise ValueError("Initial delay %s must be less than or equal"
                          " to the provided max delay %s"
                          % (initial_delay, max_delay))
     # This does a spin-loop that backs off by doubling the delay
     # up to the provided max-delay. In the future we could try having
     # a secondary client connected into redis pubsub and use that
     # instead, but for now this is simpler.
     w = timeutils.StopWatch(duration=timeout)
     w.start()
     delay = initial_delay
     while True:
         jc = self.job_count
         if jc > 0:
             curr_jobs = self._fetch_jobs()
             if curr_jobs:
                 return base.JobBoardIterator(
                     self, LOG,
                     board_fetch_func=lambda ensure_fresh: curr_jobs)
         if w.expired():
             raise exc.NotFound("Expired waiting for jobs to"
                                " arrive; waited %s seconds"
                                % w.elapsed())
         else:
             remaining = w.leftover(return_none=True)
             if remaining is not None:
                 delay = min(delay * 2, remaining, max_delay)
             else:
                 delay = min(delay * 2, max_delay)
             sleep_func(delay)
コード例 #2
0
 def wait(self, timeout=None):
     # Wait until timeout expires (or forever) for jobs to appear.
     watch = timeutils.StopWatch(duration=timeout)
     watch.start()
     with self._job_cond:
         while True:
             if not self._known_jobs:
                 if watch.expired():
                     raise excp.NotFound("Expired waiting for jobs to"
                                         " arrive; waited %s seconds" %
                                         watch.elapsed())
                 # This is done since the given timeout can not be provided
                 # to the condition variable, since we can not ensure that
                 # when we acquire the condition that there will actually
                 # be jobs (especially if we are spuriously awaken), so we
                 # must recalculate the amount of time we really have left.
                 self._job_cond.wait(watch.leftover(return_none=True))
             else:
                 curr_jobs = self._fetch_jobs()
                 fetch_func = lambda ensure_fresh: curr_jobs
                 removal_func = lambda a_job: self._remove_job(a_job.path)
                 return base.JobBoardIterator(
                     self,
                     LOG,
                     board_fetch_func=fetch_func,
                     board_removal_func=removal_func)
コード例 #3
0
ファイル: impl_redis.py プロジェクト: wangaling/taskflow
 def iterjobs(self, only_unclaimed=False, ensure_fresh=False):
     return base.JobBoardIterator(
         self,
         LOG,
         only_unclaimed=only_unclaimed,
         ensure_fresh=ensure_fresh,
         board_fetch_func=lambda ensure_fresh: self._fetch_jobs())
コード例 #4
0
 def iterjobs(self, only_unclaimed=False, ensure_fresh=False):
     board_removal_func = lambda job: self._remove_job(job.path)
     return base.JobBoardIterator(self,
                                  LOG,
                                  only_unclaimed=only_unclaimed,
                                  ensure_fresh=ensure_fresh,
                                  board_fetch_func=self._fetch_jobs,
                                  board_removal_func=board_removal_func)