Exemplo n.º 1
0
Arquivo: core.py Projeto: yinlj/w5
    def exposed_exec(self,
                     uuid=None,
                     timer_app=None,
                     w_timer_app=None,
                     controller_data=None):
        self.uuid = uuid
        self.timer_app = timer_app
        self.w_timer_app = w_timer_app
        self.controller_data = controller_data

        if self.timer_app == "" and str(self.w_timer_app) != "":
            self.exposed_remove()
        elif self.timer_app != "" and str(self.w_timer_app) != "":
            if self.timer_app == self.w_timer_app:
                timer_info = Timer.select("timer_uuid").where(
                    'timer_uuid', self.timer_app).first()
                if timer_info:
                    self.update_timer()
                else:
                    self.add_timer()
            else:
                self.exposed_remove()
                self.add_timer()
        elif self.timer_app != "" and str(self.w_timer_app) == "":
            self.add_timer()
Exemplo n.º 2
0
Arquivo: core.py Projeto: yinlj/w5
    def start(self):
        w5_timer.create_scheduler()
        w5_timer.start()

        timer_list = Timer.select("timer_uuid", "uuid", "type",
                                  "interval_type", "time", "start_date",
                                  "end_date", "jitter", "status").get()

        count = 0

        for t in timer_list:
            if count == 0:
                logger.info("============== 任务调度恢复中 =================")

            if t.start_date == "":
                t.start_date = None

            if t.end_date == "":
                t.end_date = None

            if t.type == "date":
                w5_timer.add_date(run_date=t.time,
                                  uuid=t.uuid,
                                  timer_uuid=t.timer_uuid)
            elif t.type == "interval":
                w5_timer.add_interval(t.interval_type,
                                      int(t.time),
                                      uuid=t.uuid,
                                      timer_uuid=t.timer_uuid,
                                      start_date=t.start_date,
                                      end_date=t.end_date,
                                      jitter=t.jitter)
            elif t.type == "cron":
                w5_timer.add_cron(t.time,
                                  uuid=t.uuid,
                                  timer_uuid=t.timer_uuid,
                                  start_date=t.start_date,
                                  end_date=t.end_date,
                                  jitter=t.jitter)

            if str(t.status) == "0":
                w5_timer.pause(t.timer_uuid)

            logger.info("{timer_uuid} {type} {time}",
                        timer_uuid=t.timer_uuid,
                        type=t.type,
                        time=t.time)

            count = count + 1

        if count > 0:
            logger.info("============== 任务调度恢复完成 =================")