|
|
|
@ -21,8 +21,47 @@ class crontab_api: |
|
|
|
|
def listApi(self): |
|
|
|
|
_list = public.M('crontab').where('', ()).field('id,name,type,where1,where_hour,where_minute,echo,addtime,status,save,backup_to,stype,sname,sbody,urladdress').limit( |
|
|
|
|
'0,5').order('id desc').select() |
|
|
|
|
|
|
|
|
|
data = [] |
|
|
|
|
for i in range(len(_list)): |
|
|
|
|
tmp = _list[i] |
|
|
|
|
if _list[i]['type'] == "day": |
|
|
|
|
tmp['type'] = '每天' |
|
|
|
|
tmp['cycle'] = public.getInfo('每天, {1}点{2}分 执行', (str( |
|
|
|
|
_list[i]['where_hour']), str(_list[i]['where_minute']))) |
|
|
|
|
elif _list[i]['type'] == "day-n": |
|
|
|
|
tmp['type'] = public.getInfo( |
|
|
|
|
'每{1}天', (str(_list[i]['where1']),)) |
|
|
|
|
tmp['cycle'] = public.getInfo('每隔{1}天, {2}点{3}分 执行', (str( |
|
|
|
|
_list[i]['where1']), str(_list[i]['where_hour']), str(_list[i]['where_minute']))) |
|
|
|
|
elif _list[i]['type'] == "hour": |
|
|
|
|
tmp['type'] = '每小时' |
|
|
|
|
tmp['cycle'] = public.getInfo( |
|
|
|
|
'每小时, 第{1}分钟 执行', (str(_list[i]['where_minute']),)) |
|
|
|
|
elif _list[i]['type'] == "hour-n": |
|
|
|
|
tmp['type'] = public.getInfo( |
|
|
|
|
'每{1}小时', (str(_list[i]['where1']),)) |
|
|
|
|
tmp['cycle'] = public.getInfo('每{1}小时, 第{2}分钟 执行', (str( |
|
|
|
|
_list[i]['where1']), str(_list[i]['where_minute']))) |
|
|
|
|
elif _list[i]['type'] == "minute-n": |
|
|
|
|
tmp['type'] = public.getInfo( |
|
|
|
|
'每{1}分钟', (str(_list[i]['where1']),)) |
|
|
|
|
tmp['cycle'] = public.getInfo( |
|
|
|
|
'每隔{1}分钟执行', (str(_list[i]['where1']),)) |
|
|
|
|
elif _list[i]['type'] == "week": |
|
|
|
|
tmp['type'] = '每周' |
|
|
|
|
if not _list[i]['where1']: |
|
|
|
|
_list[i]['where1'] = '0' |
|
|
|
|
tmp['cycle'] = public.getInfo('每周{1}, {2}点{3}分执行', (self.toWeek(int( |
|
|
|
|
_list[i]['where1'])), str(_list[i]['where_hour']), str(_list[i]['where_minute']))) |
|
|
|
|
elif _list[i]['type'] == "month": |
|
|
|
|
tmp['type'] = '每月' |
|
|
|
|
tmp['cycle'] = public.getInfo('每月, {1}日 {2}点{3}分执行', (str(_list[i]['where1']), str( |
|
|
|
|
_list[i]['where_hour']), str(_list[i]['where_minute']))) |
|
|
|
|
data.append(tmp) |
|
|
|
|
|
|
|
|
|
_ret = {} |
|
|
|
|
_ret['data'] = _list |
|
|
|
|
_ret['data'] = data |
|
|
|
|
|
|
|
|
|
count = public.M('crontab').where('', ()).count() |
|
|
|
|
_page = {} |
|
|
|
@ -32,6 +71,9 @@ class crontab_api: |
|
|
|
|
_ret['page'] = public.getPage(_page) |
|
|
|
|
return public.getJson(_ret) |
|
|
|
|
|
|
|
|
|
def logsApi(self): |
|
|
|
|
return public.returnJson(False, '添加失败') |
|
|
|
|
|
|
|
|
|
def addApi(self): |
|
|
|
|
name = request.form.get('name', '') |
|
|
|
|
type = request.form.get('type', '') |
|
|
|
@ -44,6 +86,7 @@ class crontab_api: |
|
|
|
|
sName = request.form.get('sName', '') |
|
|
|
|
sBody = request.form.get('sBody', '') |
|
|
|
|
urladdress = request.form.get('urladdress', '') |
|
|
|
|
|
|
|
|
|
if len(name) < 1: |
|
|
|
|
return public.returnJson(False, '任务名称不能为空!') |
|
|
|
|
|
|
|
|
@ -62,3 +105,19 @@ class crontab_api: |
|
|
|
|
except Exception as e: |
|
|
|
|
return public.returnJson(False, '删除失败') |
|
|
|
|
##### ----- start ----- ### |
|
|
|
|
|
|
|
|
|
# 转换大写星期 |
|
|
|
|
def toWeek(self, num): |
|
|
|
|
wheres = { |
|
|
|
|
0: '日', |
|
|
|
|
1: '一', |
|
|
|
|
2: '二', |
|
|
|
|
3: '三', |
|
|
|
|
4: '四', |
|
|
|
|
5: '五', |
|
|
|
|
6: '六' |
|
|
|
|
} |
|
|
|
|
try: |
|
|
|
|
return wheres[num] |
|
|
|
|
except: |
|
|
|
|
return '' |
|
|
|
|