def on_error(exc, intervals, _): consumer.cancel() consume_error = "Task queue is not available: %s\nTrying to consume again %s..." interval = next(intervals) error(consume_error, exc, humanize_seconds(interval, 'in', ' ')) return interval
def on_error(exc, intervals, retries): interval = next(intervals) err_msg = RECEIVER_RETRY_ERROR % \ {'receiver': retry_fun, 'when': humanize_seconds(interval, 'in', ' ')} logger.error(err_msg) return interval
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.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 on_error(exc, intervals, retries): interval = next(intervals) err_msg = RECEIVER_RETRY_ERROR % { "receiver": retry_fun, "when": humanize_seconds(interval, "in", " "), } logger.error(err_msg) return interval
def _error_handler(exc, interval, next_step=CONNECTION_RETRY_STEP): if getattr(conn, 'alt', None) and interval == 0: next_step = CONNECTION_FAILOVER next_step = next_step.format( when=humanize_seconds(interval, 'in', ' '), retries=int(interval / 2), max_retries=self.app.conf.broker_connection_max_retries) error(CONNECTION_ERROR, conn.as_uri(), exc, next_step)
def info(self): info = [ ' . redis -> {}'.format( maybe_sanitize_url(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 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(scheduler.max_interval), max_interval=scheduler.max_interval, )
def start(self, embedded_process=False): info('beat: Starting...') debug('beat: 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('celery beat') try: while not self._is_shutdown.is_set(): interval = self.scheduler.tick() if interval and interval > 0.0: debug('beat: Waking up %s.', humanize_seconds(interval, prefix='in ')) time.sleep(interval) if self.scheduler.should_sync(): self.scheduler._do_sync() except (KeyboardInterrupt, SystemExit): self._is_shutdown.set() finally: self.sync()
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 on_connection_error(self, max_retries, exc, intervals, retries): tts = next(intervals) logger.error( E_LOST.strip(), retries, max_retries or 'Inf', humanize_seconds(tts, 'in ')) return tts
def on_connection_error(self, max_retries, exc, intervals, retries): tts = next(intervals) logger.error(E_LOST.strip(), retries, max_retries or 'Inf', humanize_seconds(tts, 'in ')) return tts
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 test_humanize_seconds__prefix(): assert humanize_seconds(4, prefix='about ') == 'about 4.00 seconds'
def test_humanize_seconds(seconds, expected): assert humanize_seconds(seconds) == expected
def human_seconds(self): return humanize_seconds(self.seconds)
def _error_handler(exc, interval): dumper.say(CONNECTION_ERROR % ( conn.as_uri(), exc, humanize_seconds(interval, 'in', ' ') ))
def humanize_seconds(secs, prefix='', sep='', now='now', **kwargs): s = timeutils.humanize_seconds(secs, prefix, sep, now, **kwargs) if s == now and float(secs) > 0: return '{prefix}{sep}{0:.2f} seconds'.format( float(secs), prefix=prefix, sep=sep) return s
def on_error(self, exc, intervals, _): msg = "Critical object is not available: %s\nTrying to consume again %s..." interval = next(intervals) logger.debug(msg, exc, humanize_seconds(interval, 'in', ' ')) return interval
import pytz from datetime import datetime from celery.utils.time import humanize_seconds # from cq import celery_app import pandas as pd redis = schedulers.get_redis(celery_app) conf = schedulers.RedBeatConfig(celery_app) keys = redis.zrange(conf.schedule_key, 0, -1) utcnow = pytz.utc.localize(datetime.utcnow()) entries = [ schedulers.RedBeatSchedulerEntry.from_key(key, app=celery_app) for key in keys ] # pprint(entries) entry_data = [] for entry in entries: e = entry.__dict__ e["due_at"] = entry.due_at e["due_in"] = humanize_seconds( (entry.due_at - utcnow).total_seconds(), prefix="in " ) entry_data.append(e) df = pd.DataFrame(entry_data) # df = df.drop(columns=["app", "task", "args"]) print(df)