Exemplo n.º 1
0
    def __init__(self, stor, iden, recur, indx, query, creator, recs, nexttime=None):
        self.doc = ''
        self.name = ''
        self.stor = stor
        self.iden = iden
        self.recur = recur # does this appointment repeat
        self.indx = indx  # incremented for each appt added ever.  Used for nexttime tiebreaking for stable ordering
        self.query = query  # query to run
        self.creator = creator # user iden to run query as
        self.recs = recs  # List[ApptRec]  list of the individual entries to calculate next time from
        self._recidxnexttime = None # index of rec who is up next

        if self.recur and not self.recs:
            raise s_exc.BadTime(mesg='A recurrent appointment with no records')

        if nexttime is None and self.recs:
            now = time.time()
            self.nexttime = now
            self.updateNexttime(now + 1.0)  # lie slightly about the time so it does advance
            if self.nexttime is None:
                raise s_exc.BadTime(mesg='Appointment is in the past')
        else:
            self.nexttime = nexttime
        self.isrunning = False  # whether it is currently running
        self.startcount = 0  # how many times query has started
        self.laststarttime = None
        self.lastfinishtime = None
        self.lastresult = None
        self.enabled = True
Exemplo n.º 2
0
    def __init__(self, stor, iden, recur, indx, query, creator, recs, nexttime=None, view=None):
        self.doc = ''
        self.name = ''
        self.stor = stor
        self.iden = iden
        self.recur = recur  # does this appointment repeat
        self.indx = indx  # incremented for each appt added ever.  Used for nexttime tiebreaking for stable ordering
        self.query = query  # query to run
        self.creator = creator  # user iden to run query as
        self.recs = recs  # List[ApptRec]  list of the individual entries to calculate next time from
        self._recidxnexttime = None  # index of rec who is up next
        self.view = view

        if self.recur and not self.recs:
            raise s_exc.BadTime(mesg='A recurrent appointment with no records')

        if nexttime is None and self.recs:
            self.nexttime = self.stor._getNowTick()
            self.updateNexttime(self.nexttime)
            if self.nexttime is None:
                raise s_exc.BadTime(mesg='Appointment is in the past')
        else:
            self.nexttime = nexttime
        self.isrunning = False  # whether it is currently running
        self.startcount = 0  # how many times query has started
        self.errcount = 0  # how many times this appt failed
        self.lasterrs = collections.deque((), maxlen=5)
        self.laststarttime = None
        self.lastfinishtime = None
        self.lastresult = None
        self.enabled = True
Exemplo n.º 3
0
    def __init__(self, reqdict, incunit=None, incval=1):
        self.reqdict = reqdict
        self.incunit = incunit
        self.incval = incval if incunit is not None else None

        if not reqdict and incunit is None:
            raise s_exc.BadTime(
                mesg='reqdict must be nonempty or incunit must be non-None')

        if TimeUnit.DAY in reqdict:
            raise s_exc.BadTime(mesg='Must not specify day as requirement')

        if TimeUnit.DAYOFMONTH in reqdict and TimeUnit.DAYOFWEEK in reqdict:
            raise s_exc.BadTime(
                mesg=
                'Both day of month and day of week must not both be requirements'
            )

        if TimeUnit.DAYOFWEEK in reqdict and incunit is not None:
            raise s_exc.BadTime(
                mesg='Day of week requirement not supported with a recurrence')

        if incunit == TimeUnit.DAYOFMONTH:
            raise s_exc.BadTime(mesg='Day of month not a valid incunit')

        if incunit is not None:
            boundmin, boundmax = _UnitBounds[incunit][1]
            if not boundmin <= incval <= boundmax:
                raise s_exc.BadTime(mesg='Out of bounds incval')

        for reqkey, reqval in reqdict.items():
            if reqkey not in TimeUnit:
                raise s_exc.BadTime(
                    mesg=
                    'Keys of reqdict parameter must be valid TimeUnit values')
            boundmin, boundmax = _UnitBounds[reqkey][0]
            if not boundmin <= reqval <= boundmax:
                raise s_exc.BadTime(mesg='Out of bounds reqdict value')

            if incunit is not None and reqkey <= incunit:
                # We could, actually support this, but most of these combinations are nonsensical (e.g. run every 5
                # minutes in 2018 only?)
                raise s_exc.BadTime(
                    mesg=
                    'Must not have fixed unit equal to or greater than recurrence unit'
                )

        self.reqdict = {}
        # Put keys in size order, with dayof... added last, as nexttime processes in that order
        for key in _NextUnitMap:
            if key in reqdict:
                self.reqdict[key] = reqdict[key]
Exemplo n.º 4
0
 async def stream(self, doraise=False):
     yield 1
     yield 2
     if doraise:
         raise s_exc.BadTime(mesg='call again later')