# Path: pq/utils/time.py
# def timedelta_seconds(delta):
#     return max(delta.total_seconds(), 0)


import time
from datetime import datetime, timedelta
from pulsar.utils.log import lazyproperty
from ..utils.time import timedelta_seconds

    .. attribute:: total_run_count

        Total number of times this periodic task has been executed by the
        :class:`.TaskBackend`.
    '''

    def __init__(self, name, run_every, anchor=None):
        self.name = name
        self.run_every = run_every
        self.anchor = anchor
        self.last_run_at = datetime.now()
        self.total_run_count = 0

    def __repr__(self):
        return self.name

    __str__ = __repr__

    @property
    def scheduled_last_run_at(self):
        '''The scheduled last run datetime.

        This is different from :attr:`last_run_at` only when
        :attr:`anchor` is set.
        '''
        last_run_at = self.last_run_at
        anchor = self.anchor
        if last_run_at and anchor:
            run_every = self.run_every

# Path: pq/utils/time.py
# def timedelta_seconds(delta):
#     return max(delta.total_seconds(), 0)


# Path: pq/tasks/scheduler.py
import time
from datetime import datetime, timedelta
from pulsar.utils.log import lazyproperty
from ..utils.time import timedelta_seconds


    .. attribute:: total_run_count

        Total number of times this periodic task has been executed by the
        :class:`.TaskBackend`.
    '''

    def __init__(self, name, run_every, anchor=None):
        self.name = name
        self.run_every = run_every
        self.anchor = anchor
        self.last_run_at = datetime.now()
        self.total_run_count = 0

    def __repr__(self):
        return self.name

    __str__ = __repr__

    @property
    def scheduled_last_run_at(self):
        '''The scheduled last run datetime.

        This is different from :attr:`last_run_at` only when
        :attr:`anchor` is set.
        '''
        last_run_at = self.last_run_at
        anchor = self.anchor
        if last_run_at and anchor:
            run_every = self.run_every

            times = int(timedelta_seconds(last_run_at - anchor) /