Beispiel #1
0
    def test_cron_task(self):
        self.check_OK("/system/crontab/add", method="POST", data=dict(url="test", tm_wday="*", tm_hour="*", tm_min="*"))
        sched = xtables.get_schedule_table().select_first(where=dict(url="test"))
        self.check_OK("/system/crontab/remove?id={}".format(sched.id))

        self.check_OK("/system/crontab/add", method="POST", data=dict(script_url="script://test.py", tm_wday="1", tm_hour="*", tm_min="*"))
        sched2 = xtables.get_schedule_table().select_first(where=dict(url="script://test.py"))
        self.check_OK("/system/crontab/remove?id={}".format(sched2.id))
Beispiel #2
0
 def check_and_run(task, tm):
     if self.match(task, tm):
         put_task(request_url, task)
         try:
             xutils.trace("RunTask",  task.url)
             if task.tm_wday == "no-repeat":
                 # 一次性任务直接删除
                 xtables.get_schedule_table().delete(where=dict(id=task.id))
                 self.load_tasks()
         except Exception as e:
             xutils.log("run task [%s] failed, %s" % (task.url, e))
Beispiel #3
0
    def POST(self):
        id = xutils.get_argument("id")
        name = xutils.get_argument("name")
        url  = xutils.get_argument("url")
        tm_wday = xutils.get_argument("tm_wday")
        tm_hour = xutils.get_argument("tm_hour")
        tm_min  = xutils.get_argument("tm_min")
        message = xutils.get_argument("message")
        sound_value = xutils.get_argument("sound")
        webpage_value = xutils.get_argument("webpage")
        sound = 1 if sound_value == "on" else 0
        webpage = 1 if webpage_value == "on" else 0

        db = xtables.get_schedule_table()
        if id == "" or id is None:
            db.insert(name=name, url=url, mtime=xutils.format_datetime(), 
                ctime=xutils.format_datetime(),
                tm_wday = tm_wday,
                tm_hour = tm_hour,
                tm_min = tm_min,
                message = message,
                sound = sound,
                webpage = webpage)
        else:
            id = int(id)
            db.update(where=dict(id=id), name=name, url=url, 
                mtime=xutils.format_datetime(),
                tm_wday = tm_wday,
                tm_hour = tm_hour,
                tm_min = tm_min,
                message = message,
                sound = sound,
                webpage = webpage)
        xmanager.load_tasks()
        raise web.seeother("/file/group/memo")
Beispiel #4
0
    def add_request_old(self):
        url = xutils.get_argument("url")
        # interval = xutils.get_argument("interval", 10, type=int)
        repeat_type = xutils.get_argument("repeat_type", "day")
        pattern = xutils.get_argument("pattern")

        if repeat_type == "interval":
            interval = int(pattern)
        else:
            interval = -1
            if pattern.count(":") == 1:
                # 如果是分钟默认加上秒
                pattern = pattern + ":00"

        db = xtables.get_schedule_table()
        rows = db.select(where="url=$url", vars=dict(url=url))
        result = rows.first()
        if result is None:
            db.insert(url=url,
                      interval=interval,
                      pattern=pattern,
                      ctime=xutils.format_time(),
                      mtime=xutils.format_time(),
                      repeat_type=repeat_type)
        else:
            db.update(where=dict(url=url),
                      interval=interval,
                      pattern=pattern,
                      mtime=xutils.format_time(),
                      repeat_type=repeat_type)

        xmanager.instance().load_tasks()
        raise web.seeother("/system/crontab")
Beispiel #5
0
def search(delay_mins, message):
    if not xauth.is_admin():
        return []
    db = xtables.get_schedule_table()
    url = "/api/alarm/" + message

    millis = time.time() + int(delay_mins) * 60
    tm = time.localtime(millis)
    tm_wday = "no-repeat"
    tm_hour = tm.tm_hour
    tm_min = tm.tm_min

    db.insert(url=url,
              ctime=xutils.format_time(),
              mtime=xutils.format_time(),
              tm_wday=tm_wday,
              tm_hour=tm_hour,
              tm_min=tm_min)

    xmanager.load_tasks()

    result = SearchResult()
    result.name = "提醒"
    result.raw = "提醒创建成功,将于%s提醒 %s" % (xutils.format_time(millis), message)
    return [result]
Beispiel #6
0
def migrate_schedule():
    db = xtables.get_schedule_table()
    for item in db.select():
        key = "schedule:%s" % item.id
        data = dbutil.get(key)
        if data is None:
            dbutil.put(key, item)
    return "迁移完成!"
Beispiel #7
0
 def load_tasks(self):
     schedule       = xtables.get_schedule_table()
     tasks          = schedule.select(order="url")
     self.task_list = list(tasks)
     # 系统默认的任务
     backup_task = xutils.Storage(name="[系统]备份", url="/system/backup", 
         tm_wday = "*", tm_hour="11", tm_min="0", 
         message = "", sound=0, webpage=0, id=None)
     self.task_list.append(backup_task)
Beispiel #8
0
    def GET(self):
        db = xtables.get_schedule_table()
        # files = db.select()
        files = xmanager.get_task_list()

        def set_display_name(file):
            file.display_name = file.name if file.name != "" else file.url
            return file

        files = list(map(set_display_name, files))
        return xtemplate.render("file/view.html",
                                pathlist=[PathNode("备忘录", "/file/group/memo")],
                                file_type="memo",
                                files=files)
Beispiel #9
0
def add_alarm(tm_hour, tm_min, message):
    db = xtables.get_schedule_table()
    url = "/api/alarm"
    tm_wday = "no-repeat"
    name = "[提醒] %s" % message

    db.insert(name=name,
            url=url,
            message=message,
            ctime=xutils.format_time(),
            mtime=xutils.format_time(),
            tm_wday=tm_wday,
            tm_hour=tm_hour,
            tm_min=tm_min)
    xmanager.load_tasks()
Beispiel #10
0
    def POST(self):
        script_url = xutils.get_argument("script_url")
        url = xutils.get_argument("url")
        # url = xutils.quote_unicode(url)
        tm_wday = xutils.get_argument("tm_wday")
        tm_hour = xutils.get_argument("tm_hour")
        tm_min = xutils.get_argument("tm_min")

        if script_url != "" and script_url != None:
            url = script_url

        if url == "":
            raise web.seeother("/system/crontab")

        db = xtables.get_schedule_table()
        db.insert(url=url,
                  ctime=xutils.format_time(),
                  mtime=xutils.format_time(),
                  tm_wday=tm_wday,
                  tm_hour=tm_hour,
                  tm_min=tm_min)
        xmanager.instance().load_tasks()
        raise web.seeother("/system/crontab")
Beispiel #11
0
 def GET(self):
     id = xutils.get_argument("id", type=int)
     db = xtables.get_schedule_table()
     db.delete(where=dict(id=id))
     xmanager.load_tasks()
     raise web.seeother("/file/group/memo")
Beispiel #12
0
 def GET(self):
     id = xutils.get_argument("id", type=int)
     sched = xtables.get_schedule_table().select_one(where=dict(id=id))
     return xtemplate.render("file/memo_edit.html", item = sched)
Beispiel #13
0
 def GET(self):
     id = xutils.get_argument("id", type=int)
     sched = xtables.get_schedule_table().select_one(where=dict(id=id))
     return xtemplate.render("system/crontab_edit.html",
                             item=sched,
                             links=get_cron_links())
Beispiel #14
0
 def POST(self):
     id = xutils.get_argument("id", type=int)
     xtables.get_schedule_table().delete(where=dict(id=id))
     xmanager.load_tasks()
     raise web.seeother("/system/crontab")