예제 #1
0
    def add_timer(self):
        self.load_config()

        if self.config["type"] == "date":
            w5_timer.add_date(run_date=self.config["time"], uuid=self.uuid, timer_uuid=self.timer_app)
        elif self.config["type"] == "interval":
            w5_timer.add_interval(self.config["interval_type"], int(self.config["time"]), uuid=self.uuid,
                                  timer_uuid=self.timer_app,
                                  start_date=self.config["start_date_x"],
                                  end_date=self.config["end_date_x"],
                                  jitter=self.config["jitter"])
        elif self.config["type"] == "cron":
            w5_timer.add_cron(self.config["time"], uuid=self.uuid, timer_uuid=self.timer_app,
                              start_date=self.config["start_date_x"],
                              end_date=self.config["end_date_x"],
                              jitter=self.config["jitter"])

        w5_timer.pause(self.timer_app)

        Timer.insert({
            'timer_uuid': self.timer_app,
            'uuid': self.uuid,
            "type": self.config["type"],
            'interval_type': self.config["interval_type"],
            'time': self.config["time"],
            'start_date': self.config["start_date"],
            'end_date': self.config["end_date"],
            'jitter': self.config["jitter"],
            'status': 0,
            'update_time': Time.get_date_time(),
            'create_time': Time.get_date_time()
        })
예제 #2
0
    def exposed_pause_all(self):
        w5_timer.pause_all()

        Timer.where("id", "!=", "0").update({
            'status': 0,
            'update_time': Time.get_date_time()
        })
예제 #3
0
    def exposed_resume_all(self):
        w5_timer.resume_all()

        Timer.where("id", "!=", "0").update({
            'status': 1,
            'update_time': Time.get_date_time()
        })
예제 #4
0
 def exposed_remove(self, timer_app=None):
     if timer_app:
         Timer.where('timer_uuid', timer_app).delete()
         w5_timer.remove_job(timer_app)
     else:
         Timer.where('timer_uuid', self.w_timer_app).delete()
         w5_timer.remove_job(self.w_timer_app)
예제 #5
0
파일: core.py 프로젝트: yinlj/w5
    def update_timer(self):
        self.load_config()

        if self.config["type"] == "date":
            w5_timer.update_date(self.timer_app, self.config["time"])
        elif self.config["type"] == "interval":
            w5_timer.update_interval(self.timer_app,
                                     self.config["interval_type"],
                                     int(self.config["time"]),
                                     start_date=self.config["start_date_x"],
                                     end_date=self.config["end_date_x"],
                                     jitter=self.config["jitter"])
        elif self.config["type"] == "cron":
            w5_timer.update_cron(self.timer_app,
                                 self.config["time"],
                                 start_date=self.config["start_date_x"],
                                 end_date=self.config["end_date_x"],
                                 jitter=self.config["jitter"])

        Timer.where('timer_uuid', self.timer_app).update({
            "type":
            self.config["type"],
            'interval_type':
            self.config["interval_type"],
            'time':
            self.config["time"],
            'start_date':
            self.config["start_date"],
            'end_date':
            self.config["end_date"],
            'jitter':
            self.config["jitter"],
            'update_time':
            Time.get_date_time()
        })
예제 #6
0
    def exposed_resume(self, uuid=None):
        if uuid:
            w5_timer.resume(uuid=uuid)

            Timer.where('timer_uuid', uuid).update({
                'status': 1,
                'update_time': Time.get_date_time()
            })
        else:
            w5_timer.resume(uuid=self.w_timer_app)

            Timer.where('timer_uuid', self.w_timer_app).update({
                'status': 1,
                'update_time': Time.get_date_time()
            })
예제 #7
0
파일: core.py 프로젝트: 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()
예제 #8
0
파일: core.py 프로젝트: 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("============== 任务调度恢复完成 =================")