예제 #1
0
파일: schedule.py 프로젝트: jdost/lazbot
    def __init__(self, action=None, delta=None, when=None, recurring=None, name=None):
        if not when and not delta:
            raise "Need a time or time span to schedule at"

        if not name:
            name = action.__name__

        if type(when) == time:
            today = date.today()
            now = datetime.now(tzutc()).timetz()
            when = datetime.combine(today if now < when else today + timedelta(days=1), when)
        elif type(when) == date:
            when = datetime.combine(when, time(0, 0, tzinfo=tzutc()))

        if delta and not when:  # provide a period but no start
            self.delta = delta
            self.next = datetime.now(tzutc()) + delta
        elif when and not delta:  # provide a start but no period
            self.delta = when - datetime.now(tzutc())
            self.next = when
        else:  # provide a start and period, this should always be recurring
            self.delta = delta
            self.next = when

        self.recurring = recurring
        self.done = False
        self.name = name

        Hook.__init__(self, events.TASK, clean_args(action if action else identity))
        logger.debug(self)
예제 #2
0
파일: lazbot.py 프로젝트: jdost/lazbot
    def __init__(self, token):
        self.token = token
        self._initialize()

        self.schedule(self.__cleanup, after=timedelta(minutes=1),
                      recurring=True)

        Model.bind_bot(self)
        Hook.bind_bot(self)
예제 #3
0
파일: schedule.py 프로젝트: jdost/lazbot
    def __call__(self, quiet=False, *args, **kwargs):
        if self.done:
            return
        elif self.recurring:
            self.next = datetime.now(tzutc()) + self.delta
        else:
            self.done = True

        with self.context():
            if not quiet:
                logger.debug(self)
            return self.handler(*args, **kwargs) if self.handler else Hook.removed()