From 04c10f5ca2b3dfd782c06a9a411f1060703090eb Mon Sep 17 00:00:00 2001 From: Stuart Axon Date: Mon, 13 Jun 2016 16:02:38 +0100 Subject: [PATCH] Update timer.py Make ```to_timestamp``` monotonic. Without this fix the countdown and eta examples from the celery docs were not working. https://github.com/celery/celery/issues/3217 --- kombu/async/timer.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kombu/async/timer.py b/kombu/async/timer.py index 584f0d2e..3861d019 100644 --- a/kombu/async/timer.py +++ b/kombu/async/timer.py @@ -20,6 +20,7 @@ from vine.utils import wraps from kombu.five import monotonic, python_2_unicode_compatible from kombu.log import get_logger +from time import time as _time try: from pytz import utc @@ -37,11 +38,12 @@ IS_PYPY = hasattr(sys, 'pypy_version_info') scheduled = namedtuple('scheduled', ('eta', 'priority', 'entry')) -def to_timestamp(d, default_timezone=utc): +def to_timestamp(d, default_timezone=utc, time=monotonic): if isinstance(d, datetime): if d.tzinfo is None: d = d.replace(tzinfo=default_timezone) - return max((d - EPOCH).total_seconds(), 0) + diff = _time() - time() + return max((d - EPOCH).total_seconds() - diff, 0) return d