예제 #1
0
    def scheduleOneTask(self, task, immediate=False):
        if immediate:
            waitTime = 0
        else:
            waitTime = self.tactic(task) + 1
        t = time.gmtime()
        curtime = datetime.datetime(t[0], t[1], t[2], t[3], t[4], t[5], tzinfo=timezone.GMT())
        dt = curtime + datetime.timedelta(seconds=waitTime)

        dateFormat = dt.astimezone(timezone.getTimeZone(globalProperty.getTimeZone())).strftime(
            "%Y-%m-%d %H:%M:%S %A (%Z)"
        )

        # content = globalProperty.getRestSchTkMgrInstance().getContentOfJob(task['fileName'])
        self._dbutil.addNewScheduleJob(task, self.type, dateFormat)
        self.logger.info("Task %s will be kicked off on %s" % (str(task["fileName"]), dateFormat))

        fileName = task["fileName"]
        funcArgs = [str(fileName)]
        funcKwargs = task
        t = Timer(waitTime, self.popUpTaskHandle, funcArgs, funcKwargs)
        timerName = "timer_%s" % fileName
        t.setName(timerName)
        t.start()

        # Record timer
        self.__timerDic[fileName] = t
예제 #2
0
 def tactic(self, task):
     startDate = task['startDate']
     startTime = task['startTime']
     timezoneStr = "PST"
     if "timezone" in task:
         timezoneStr = task['timezone']
     
     dateList = startDate.split('-')
     timeList = startTime.split(':')        
     self._unicodeToInt(dateList)
     self._unicodeToInt(timeList)
     
     t = time.gmtime()
     curtime = datetime.datetime(t[0], t[1], t[2], t[3], t[4], t[5], tzinfo=timezone.GMT())
     
     #Transfer to current timezone
     tz = timezone.getTimeZone(timezoneStr)
     curdate = curtime.astimezone(tz)
     
     dateList[0] = curdate.year
     dateList[1] = curdate.month
     dateList[2] = curdate.day
     
     if task.has_key('nthday'):
         nthday = int(task['nthday'])
         schDateTime = datetime.datetime(dateList[0], dateList[1], nthday,
                                         timeList[0], timeList[1], timeList[2],
                                         tzinfo=tz)
         days, seconds = self._compareWithCurTime(schDateTime, tz)
         while days<0 and self.repeat:
             dateList[0] += self.timeTactic[0] #year
             dateList[1] += self.timeTactic[1] #month
             dateList[2] += self.timeTactic[2] #day
             schDateTime = self._makeUpSchDateTime(dateList[0], dateList[1], nthday,
                                           timeList[0], timeList[1], timeList[2], tz)
             days, seconds = self._compareWithCurTime(schDateTime, tz)
     else:
         which = int(task['whichWeekday'])
         weekday = int(task['weekday'])
         
         day = self.weekdayToDay(dateList[0], dateList[1], which, weekday)
         schDateTime = datetime.datetime(dateList[0], dateList[1], day,
                                         timeList[0], timeList[1], timeList[2],
                                         tzinfo=tz)
         days, seconds = self._compareWithCurTime(schDateTime, tz)
         while days<0 and self.repeat:
             dateList[0] += self.timeTactic[0] #year
             dateList[1] += self.timeTactic[1] #month
             dateList[2] += self.timeTactic[2] #day
             day = self.weekdayToDay(dateList[0], dateList[1], which, weekday)
             schDateTime = self._makeUpSchDateTime(dateList[0], dateList[1], day,
                                                   timeList[0], timeList[1], timeList[2], tz)
             days, seconds = self._compareWithCurTime(schDateTime, tz)
             
     gap = days * 24 * 60 * 60 + seconds
     return gap
예제 #3
0
 def tactic(self, task):
     startDate = task['startDate']
     startTime = task['startTime']
     timezoneStr = "PST"
     if "timezone" in task:
         timezoneStr = task['timezone']
                 
     dateList = startDate.split('-')
     timeList = startTime.split(':')
     self._unicodeToInt(dateList)
     self._unicodeToInt(timeList)
     
     t = time.gmtime()
     curtime = datetime.datetime(t[0], t[1], t[2], t[3], t[4], t[5], tzinfo=timezone.GMT())
     
     #Transfer to current timezone
     tz = timezone.getTimeZone(timezoneStr)
     curdate = curtime.astimezone(tz)
     
     curweekday = curdate.weekday()
     expweekday = int(task['weekday']) 
     
     dateList[0] = curdate.year
     dateList[1] = curdate.month
     dateList[2] = curdate.day + (expweekday - curweekday)
     
     schDateTime = self._makeUpSchDateTime(dateList[0], dateList[1], dateList[2],
                                           timeList[0], timeList[1], timeList[2], tz)
     days, seconds = self._compareWithCurTime(schDateTime, tz)
     while days<0 and self.repeat:
         dateList[0] += self.timeTactic[0] #year
         dateList[1] += self.timeTactic[1] #month
         dateList[2] += self.timeTactic[2] * (- math.floor(days/7))
         schDateTime = self._makeUpSchDateTime(dateList[0], dateList[1], dateList[2],
                                               timeList[0], timeList[1], timeList[2], tz)
         days, seconds = self._compareWithCurTime(schDateTime, tz)
         
     gap = days * 24 * 60 * 60 + seconds
     return gap
예제 #4
0
    def tactic(self, task):
        startDate = task["startDate"]
        startTime = task["startTime"]
        timezoneStr = "PST"
        if "timezone" in task:
            timezoneStr = task["timezone"]

        dateList = startDate.split("-")
        timeList = startTime.split(":")
        self._unicodeToInt(dateList)
        self._unicodeToInt(timeList)

        tz = timezone.getTimeZone(timezoneStr)
        schDateTime = datetime.datetime(
            dateList[0], dateList[1], dateList[2], timeList[0], timeList[1], timeList[2], tzinfo=tz
        )
        days, seconds = self._compareWithCurTime(schDateTime, tz)
        while days < 0 and self.repeat:
            if self.timeTactic[0:2] == [0, 0]:
                dateList[2] -= days
            else:
                dateList[0] += self.timeTactic[0]  # year
                dateList[1] += self.timeTactic[1]  # month
                dateList[2] += self.timeTactic[2]  # day

            schDateTime = self._makeUpSchDateTime(
                dateList[0], dateList[1], dateList[2], timeList[0], timeList[1], timeList[2], tz
            )
            # schDateTime = datetime.datetime(dateList[0], dateList[1], dateList[2],
            #                                timeList[0], timeList[1], timeList[2],
            #                                tzinfo=tz)
            days, seconds = self._compareWithCurTime(schDateTime, tz)

        gap = days * 24 * 60 * 60 + seconds
        return gap
        """
예제 #5
0
    def tactic(self, task):
        startDate = task["startDate"]
        startTime = task["startTime"]
        dayDuration = int(task["dayDuration"])  # This is to implement weekly working time such as from Monday to Friday
        dayGap = int(task["dayGap"])  # This means how many days between the task for executing
        eachTimeGap = task["eachTimeGap"]  # This means how long between same tasks for executing, unit:hour
        duration = task[
            "duration"
        ]  # This is for counting how many hours for repeating the task, and should less than 24 unit:hour
        timezoneStr = "PST"
        if "timezone" in task:
            timezoneStr = task["timezone"]

        dateList = startDate.split("-")
        startTimeList = startTime.split(":")
        self._unicodeToInt(dateList)
        self._unicodeToInt(startTimeList)

        durationList = duration.split(":")
        eachTimeGapList = eachTimeGap.split(":")
        self._unicodeToInt(durationList)
        self._unicodeToInt(eachTimeGapList)

        tz = timezone.getTimeZone(timezoneStr)
        startSchDateTime = datetime.datetime(
            dateList[0], dateList[1], dateList[2], startTimeList[0], startTimeList[1], startTimeList[2], tzinfo=tz
        )
        endDeltaSeconds = (durationList[0] * 60 + durationList[1]) * 60 + durationList[2]
        endSchDateTime = startSchDateTime + datetime.timedelta(seconds=endDeltaSeconds)
        startDays, startSeconds = self._compareWithCurTime(startSchDateTime, tz)
        endDays, endSencods = self._compareWithCurTime(endSchDateTime, tz)

        gap = 0
        if startDays < 0:
            startDaysLeft = abs(startDays) % (dayDuration + dayGap)
            endDaysLeft = abs(endDays) % (dayDuration + dayGap)

            if startDaysLeft == endDaysLeft:
                if endDaysLeft >= dayDuration:
                    dateList[2] -= startDays - (dayDuration + dayGap - startDaysLeft)
                else:
                    dateList[2] -= startDays

                schDateTime = self._makeUpSchDateTime(
                    dateList[0], dateList[1], dateList[2], startTimeList[0], startTimeList[1], startTimeList[2], tz
                )
                startDays, startSeconds = self._compareWithCurTime(schDateTime, tz)
                gap = startDays * 24 * 60 * 60 + startSeconds
            elif startDaysLeft > endDaysLeft:
                if endDaysLeft >= dayDuration:
                    dateList[2] -= startDays - (dayDuration + dayGap - startDaysLeft)
                    schDateTime = self._makeUpSchDateTime(
                        dateList[0], dateList[1], dateList[2], startTimeList[0], startTimeList[1], startTimeList[2], tz
                    )
                    startDays, startSeconds = self._compareWithCurTime(schDateTime, tz)
                    gap = startDays * 24 * 60 * 60 + startSeconds
                else:
                    gap = (eachTimeGapList[0] * 60 + eachTimeGapList[1]) * 60 + eachTimeGapList[2]
            else:
                raise "The time must be wrong"

        if gap == 0:
            gap = startDays * 24 * 60 * 60 + startSeconds

        return gap