Ejemplo n.º 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()
        })
Ejemplo n.º 2
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()
            })
Ejemplo n.º 3
0
    async def add_execute_logs(self, uuid, app_uuid, app_name, result, status, html, args=""):
        log_info = {
            'only_id': self.only_id,
            'uuid': uuid,
            'app_uuid': app_uuid,
            'app_name': app_name,
            'result': result,
            'status': status,
            'html': html,
            'args': args,
            'create_time': Time.get_date_time()
        }

        Logs.insert(log_info)

        logger.info(
            "{only_id} {uuid} {app_uuid} {app_name} {result} {status} {create_time}",
            only_id=self.only_id,
            uuid=uuid,
            app_uuid=app_uuid,
            app_name=app_name,
            result=result,
            status=status,
            create_time=log_info["create_time"]
        )

        data = {
            "method": "execute_log",
            "data": log_info
        }

        if self.socket is None:
            pass
        else:
            self.socket.send(json.dumps(data))
Ejemplo n.º 4
0
    def exposed_resume_all(self):
        w5_timer.resume_all()

        Timer.where("id", "!=", "0").update({
            'status': 1,
            'update_time': Time.get_date_time()
        })
Ejemplo n.º 5
0
    def exposed_pause_all(self):
        w5_timer.pause_all()

        Timer.where("id", "!=", "0").update({
            'status': 0,
            'update_time': Time.get_date_time()
        })
Ejemplo n.º 6
0
def auto_execute(uuid, s=None, controller_data=None, text=None, app_uuid=None):
    if controller_data is None or text is None or app_uuid is None:
        pass
    else:
        controller_data = json.loads(controller_data)

        if Auto().is_json(text):
            controller_data[app_uuid] = {"text": json.dumps(text)}
        else:
            controller_data[app_uuid] = {"text": str(text)}

        Workflow.where('uuid', uuid).update({
            'controller_data': json.dumps(controller_data),
            'update_time': Time.get_date_time()
        })

    def thread_exec():
        async def run():
            await asyncio.gather(Auto(socket=s).run(uuid=uuid))

        try:
            asyncio.run(run())
        except RuntimeError:
            asyncio.gather(Auto(socket=s).run(uuid=uuid))

    t = threading.Thread(target=thread_exec)
    t.setDaemon(True)
    t.start()
Ejemplo n.º 7
0
Archivo: core.py Proyecto: 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()
        })
Ejemplo n.º 8
0
    async def add_report(self):
        report_info = {
            'report_no': self.only_id,
            'workflow_name': self.workflow_name,
            'remarks': self.workflow_remarks,
            'create_time': Time.get_date_time()
        }

        Report.insert(report_info)
Ejemplo n.º 9
0
def auto_execute(uuid, s=None, controller_data=None, text=None, app_uuid=None):
    if controller_data is None or text is None or app_uuid is None:
        pass
    else:
        controller_data = json.loads(controller_data)
        controller_data[app_uuid] = {"text": str(text)}
        Workflow.where('uuid', uuid).update({
            'controller_data': json.dumps(controller_data),
            'update_time': Time.get_date_time()
        })

    async def run():
        await asyncio.gather(Auto(socket=s).run(uuid=uuid))

    try:
        asyncio.run(run())
    except RuntimeError as e:
        asyncio.gather(Auto(socket=s).run(uuid=uuid))