def pstatus(p): runtime = monotonic() - p.runtime elapsed = monotonic() - p.elapsed return F_PROGRESS.format( p, runtime=humanize_seconds(runtime, now=runtime), elapsed=humanize_seconds(elapsed, now=elapsed), )
def test_humanize_seconds(self): t = ((4 * 60 * 60 * 24, "4 days"), (1 * 60 * 60 * 24, "1 day"), (4 * 60 * 60, "4 hours"), (1 * 60 * 60, "1 hour"), (4 * 60, "4 minutes"), (1 * 60, "1 minute"), (4, "4.00 seconds"), (1, "1.00 second"), (4.3567631221, "4.36 seconds"), (0, "now")) for seconds, human in t: self.assertEqual(humanize_seconds(seconds), human) self.assertEqual(humanize_seconds(4, prefix="about "), "about 4.00 seconds")
def test_humanize_seconds(self): t = ((4 * 60 * 60 * 24, '4.00 days'), (1 * 60 * 60 * 24, '1.00 day'), (4 * 60 * 60, '4.00 hours'), (1 * 60 * 60, '1.00 hour'), (4 * 60, '4.00 minutes'), (1 * 60, '1.00 minute'), (4, '4.00 seconds'), (1, '1.00 second'), (4.3567631221, '4.36 seconds'), (0, 'now')) for seconds, human in t: self.assertEqual(humanize_seconds(seconds), human) self.assertEqual(humanize_seconds(4, prefix='about '), 'about 4.00 seconds')
def info(self): info = [' . redis -> {}'.format(self.app.redbeat_conf.redis_url)] if self.lock_key: info.append(' . lock -> `{}` {} ({}s)'.format( self.lock_key, humanize_seconds(self.lock_timeout), self.lock_timeout)) return '\n'.join(info)
def info(self): info = [' . redis -> {}'.format(self.app.conf.REDBEAT_REDIS_URL)] if self.lock_key: info.append(' . lock -> `{}` {} ({}s)'.format( self.lock_key, humanize_seconds(self.lock_timeout), self.lock_timeout)) return '\n'.join(info)
def runtest(self, fun, n=50, index=0, repeats=1): with blockdetection(self.block_timeout): t = time() i = 0 failed = False self.progress = Progress(fun, i, n, index, repeats, t, 0) _marker.delay(pstatus(self.progress)) try: for i in range(n): self.progress = Progress(fun, i, n, index, repeats, t, 0) print(pstatus(self.progress), end=' ') try: fun() print('-> done') except Exception as exc: print('-> {0!r}'.format(exc)) except Exception: failed = True raise finally: print('{0} {1} iterations in {2}s'.format( 'failed after' if failed else 'completed', i + 1, humanize_seconds(time() - t), )) if not failed: self.progress = Progress(fun, i, n, index, repeats, t, 1)
def humanize_seconds(secs, prefix='', sep='', now='now', **kwargs): s = timeutils.humanize_seconds(secs, prefix, sep, now, **kwargs) if s == now and secs > 0: return '{prefix}{sep}{0:.2f} seconds'.format(float(secs), prefix=prefix, sep=sep) return s
def test_humanize_seconds(self): t = ((4 * 60 * 60 * 24, "4 days"), (1 * 60 * 60 * 24, "1 day"), (4 * 60 * 60, "4 hours"), (1 * 60 * 60, "1 hour"), (4 * 60, "4 minutes"), (1 * 60, "1 minute"), (4, "4.00 seconds"), (1, "1.00 second"), (4.3567631221, "4.36 seconds"), (0, "now")) for seconds, human in t: self.assertEqual(timeutils.humanize_seconds(seconds), human) self.assertEqual(timeutils.humanize_seconds(4, prefix="about "), "about 4.00 seconds")
def _error_handler(exc, interval, next_step=CONNECTION_RETRY_STEP): if getattr(conn, "alt", None) and interval == 0: next_step = CONNECTION_FAILOVER error( CONNECTION_ERROR, conn.as_uri(), exc, next_step.format(when=humanize_seconds(interval, "in", " ")), )
def info(self): info = [" . redis -> {}".format(self.app.conf.REDBEAT_REDIS_URL)] if self.lock_key: info.append( " . lock -> `{}` {} ({}s)".format( self.lock_key, humanize_seconds(self.lock_timeout), self.lock_timeout ) ) return "\n".join(info)
def start(self, embedded_process=False): self.logger.info("Celerybeat: Starting...") self.logger.debug( "Celerybeat: " "Ticking with max interval->%s" % (humanize_seconds(self.scheduler.max_interval)) ) if embedded_process: platforms.set_process_title("celerybeat") try: try: while not self._shutdown.isSet(): interval = self.scheduler.tick() self.debug("Celerybeat: Waking up %s." % (humanize_seconds(interval, prefix="in "))) time.sleep(interval) except (KeyboardInterrupt, SystemExit): self._shutdown.set() finally: self.sync()
def start(self, embedded_process=False): self.logger.info("Celerybeat: Starting...") self.logger.debug("Celerybeat: Ticking with max interval->%s" % ( humanize_seconds(self.scheduler.max_interval))) signals.beat_init.send(sender=self) if embedded_process: signals.beat_embedded_init.send(sender=self) platforms.set_process_title("celerybeat") try: while not self._shutdown.isSet(): interval = self.scheduler.tick() self.debug("Celerybeat: Waking up %s." % ( humanize_seconds(interval, prefix="in "))) time.sleep(interval) except (KeyboardInterrupt, SystemExit): self._shutdown.set() finally: self.sync()
def startup_info(self, beat): scheduler = beat.get_scheduler(lazy=True) return STARTUP_INFO_FMT % { 'conninfo': self.app.connection().as_uri(), 'logfile': self.logfile or '[stderr]', 'loglevel': LOG_LEVELS[self.loglevel], 'loader': qualname(self.app.loader), 'scheduler': qualname(scheduler), 'scheduler_info': scheduler.info, 'hmax_interval': humanize_seconds(beat.max_interval), 'max_interval': beat.max_interval, }
def startup_info(self, beat): scheduler = beat.get_scheduler(lazy=True) return STARTUP_INFO_FMT.format( conninfo=self.app.connection().as_uri(), logfile=self.logfile or '[stderr]', loglevel=LOG_LEVELS[self.loglevel], loader=qualname(self.app.loader), scheduler=qualname(scheduler), scheduler_info=scheduler.info, hmax_interval=humanize_seconds(beat.max_interval), max_interval=beat.max_interval, )
def startup_info(self, beat): scheduler = beat.get_scheduler(lazy=True) return STARTUP_INFO_FMT % { "conninfo": self.app.broker_connection().as_uri(), "logfile": self.logfile or "[stderr]", "loglevel": LOG_LEVELS[self.loglevel], "loader": get_full_cls_name(self.app.loader.__class__), "scheduler": get_full_cls_name(scheduler.__class__), "scheduler_info": scheduler.info, "hmax_interval": humanize_seconds(beat.max_interval), "max_interval": beat.max_interval, }
def startup_info(self, beat): scheduler = beat.get_scheduler(lazy=True) return STARTUP_INFO_FMT % { "conninfo": self.app.amqp.format_broker_info(), "logfile": self.logfile or "[stderr]", "loglevel": LOG_LEVELS[self.loglevel], "loader": get_full_cls_name(self.app.loader.__class__), "scheduler": get_full_cls_name(scheduler.__class__), "scheduler_info": scheduler.info, "hmax_interval": humanize_seconds(beat.max_interval), "max_interval": beat.max_interval, }
def startup_info(self, beat): scheduler = beat.get_scheduler(lazy=True) return STARTUP_INFO_FMT % { "conninfo": self.app.broker_connection().as_uri(), "logfile": self.logfile or "[stderr]", "loglevel": LOG_LEVELS[self.loglevel], "loader": qualname(self.app.loader), "scheduler": qualname(scheduler), "scheduler_info": scheduler.info, "hmax_interval": humanize_seconds(beat.max_interval), "max_interval": beat.max_interval, }
def startup_info(self, service): scheduler = service.get_scheduler(lazy=True) return STARTUP_INFO_FMT.format( conninfo=self.app.connection().as_uri(), timestamp=datetime.now().replace(microsecond=0), logfile=self.logfile or '[stderr]', loglevel=LOG_LEVELS[self.loglevel], loader=qualname(self.app.loader), scheduler=qualname(scheduler), scheduler_info=scheduler.info, hmax_interval=humanize_seconds(service.max_interval), max_interval=service.max_interval, )
def runtest(self, fun, n=50, index=0, repeats=1): n = getattr(fun, '__iterations__', None) or n print('{0}: [[[{1}({2})]]]'.format(repeats, fun.__name__, n)) with blockdetection(self.block_timeout): with self.fbi.investigation(): runtime = elapsed = monotonic() i = 0 failed = False self.progress = Progress( fun, i, n, index, repeats, elapsed, runtime, 0, ) _marker.delay(pstatus(self.progress)) try: for i in range(n): runtime = monotonic() self.progress = Progress( fun, i + 1, n, index, repeats, runtime, elapsed, 0, ) try: fun() except StopSuite: raise except Exception as exc: print('-> {0!r}'.format(exc)) import traceback print(traceback.format_exc()) print(pstatus(self.progress)) else: print(pstatus(self.progress)) except Exception: failed = True self.speaker.beep() raise finally: print('{0} {1} iterations in {2}'.format( 'failed after' if failed else 'completed', i + 1, humanize_seconds(monotonic() - elapsed), )) if not failed: self.progress = Progress( fun, i + 1, n, index, repeats, runtime, elapsed, 1, )
def runtest(self, fun, n=50, index=0, repeats=1): print('{0}: [[[{1}({2})]]]'.format(repeats, fun.__name__, n)) with blockdetection(self.block_timeout): with self.fbi.investigation(): runtime = elapsed = monotonic() i = 0 failed = False self.progress = Progress( fun, i, n, index, repeats, elapsed, runtime, 0, ) _marker.delay(pstatus(self.progress)) try: for i in range(n): runtime = monotonic() self.progress = Progress( fun, i + 1, n, index, repeats, runtime, elapsed, 0, ) try: fun() except StopSuite: raise except Exception as exc: print('-> {0!r}'.format(exc)) print(pstatus(self.progress)) else: print(pstatus(self.progress)) except Exception: failed = True self.speaker.beep() raise finally: print('{0} {1} iterations in {2}s'.format( 'failed after' if failed else 'completed', i + 1, humanize_seconds(monotonic() - elapsed), )) if not failed: self.progress = Progress( fun, i + 1, n, index, repeats, runtime, elapsed, 1, )
def runtest(self, fun, n=50, index=0): with blockdetection(self.block_timeout): t = time() i = 0 failed = False marker('{0}: {1}({2})'.format(index, fun.__name__, n)) try: for i in range(n): print('{0} ({1})'.format(i, fun.__name__), end=' ') try: fun() print('-> done') except Exception as exc: print('-> {}'.format(exc)) except Exception: failed = True raise finally: print('{0} {1} iterations in {2}s'.format( 'failed after' if failed else 'completed', i + 1, humanize_seconds(time() - t), ))
def on_connection_error(self, max_retries, exc, intervals, retries): tts = next(intervals) error('Connection to Redis lost: Retry (%s/%s) %s.', retries, max_retries or 'Inf', humanize_seconds(tts, 'in ')) return tts
def _error_handler(exc, interval): dumper.say(CONNECTION_ERROR % (conn.as_uri(), exc, humanize_seconds(interval, 'in', ' ')))
def on_connection_error(self, max_retries, exc, intervals, retries): tts = next(intervals) error(E_LOST, retries, max_retries or 'Inf', humanize_seconds(tts, 'in ')) return tts
def pstatus(p): return F_PROGRESS.format( p, runtime=humanize_seconds(monotonic() - p.runtime, now='0 seconds'), elapsed=humanize_seconds(monotonic() - p.elapsed, now='0 seconds'), )
def _error_handler(exc, interval, next_step=CONNECTION_RETRY): if getattr(conn, 'alt', None) and interval == 0: next_step = CONNECTION_FAILOVER error(CONNECTION_ERROR, conn.as_uri(), exc, next_step.format(when=humanize_seconds(interval, 'in', ' ')))
def _error_handler(exc, interval, next_step=CONNECTION_RETRY): if getattr(conn, "alt", None) and interval == 0: next_step = CONNECTION_FAILOVER error(CONNECTION_ERROR, conn.as_uri(), exc, next_step % {"when": humanize_seconds(interval, "in", " ")})
def __repr__(self): return "<freq: %s>" % humanize_seconds( timedelta_seconds(self.run_every))
def pstatus(p): return F_PROGRESS.format( p, since=humanize_seconds(time() - p.when, now='0 seconds'))
def pstatus(p): return F_PROGRESS.format(p, since=humanize_seconds(time() - p.when, now='0 seconds'))
def humanize_seconds(secs, prefix='', sep='', now='now', **kwargs): s = timeutils.humanize_seconds(secs, prefix, sep, now, **kwargs) if s == now and secs > 0: return '{prefix}{sep}{0:.2f} seconds'.format( float(secs), prefix=prefix, sep=sep) return s
def _error_handler(exc, interval, next_step=CONNECTION_RETRY_STEP): if getattr(conn, 'alt', None) and interval == 0: next_step = CONNECTION_FAILOVER error(CONNECTION_ERROR, conn.as_uri(), exc, next_step.format(when=humanize_seconds(interval, 'in', ' ')))
def _error_handler(exc, interval): dumper.say(CONNECTION_ERROR % ( conn.as_uri(), exc, humanize_seconds(interval, 'in', ' ') ))