Skip to content

Commit

Permalink
定时任务默认倒序,显示任务总条数,whyour#22 whyour#23 whyour#173 whyour#175
Browse files Browse the repository at this point in the history
  • Loading branch information
hanhh committed May 24, 2021
1 parent 9e1ee2e commit 583fe05
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 11 deletions.
9 changes: 6 additions & 3 deletions back/api/cron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,19 @@ export default (app: Router) => {
'/crons',
celebrate({
body: Joi.object({
command: Joi.string().required(),
schedule: Joi.string().required(),
command: Joi.string().optional(),
schedule: Joi.string().optional(),
name: Joi.string().optional(),
_id: Joi.string().required(),
}),
}),
async (req: Request, res: Response, next: NextFunction) => {
const logger: Logger = Container.get('logger');
try {
if (cron_parser.parseExpression(req.body.schedule).hasNext()) {
if (
!req.body.schedule ||
cron_parser.parseExpression(req.body.schedule).hasNext()
) {
const cronService = Container.get(CronService);
const data = await cronService.update(req.body);
return res.send({ code: 200, data });
Expand Down
2 changes: 1 addition & 1 deletion back/services/cron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export default class CronService {
return new Promise((resolve) => {
this.cronDb
.find(query)
.sort({ created: 1 })
.sort({ created: -1 })
.exec((err, docs) => {
resolve(docs);
});
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
},
"devDependencies": {
"@ant-design/pro-layout": "^6.5.0",
"@ant-design/icons": "^4.6.2",
"@types/cors": "^2.8.10",
"@types/express": "^4.17.8",
"@types/express-jwt": "^6.0.1",
Expand Down
3 changes: 3 additions & 0 deletions sample/config.sample.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ HelpType=""
## 是否自动启动bot,默认不启动,设置为true时自动启动
AutoStartBot=""

## 安装bot依赖时指定pip源,默认使用清华源,如不需要源,设置此参数为空
PipMirror="https://pypi.tuna.tsinghua.edu.cn/simple"

## 需组合的环境变量列表,env_name需要和var_name一一对应,如何有新活动按照格式添加(不懂勿动)
env_name=(
JD_COOKIE
Expand Down
32 changes: 32 additions & 0 deletions shell/api.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,38 @@ update_cron_api() {
fi
}

update_cron_command_api() {
local currentTimeStamp=$(date +%s)
if [ $# -eq 1 ]; then
local command=$(echo "$1" | awk -F ":" '{print $1}')
local id=$(echo "$1" | awk -F ":" '{print $2}')
else
local command=$1
local id=$2
fi

local api=$(
curl -s "http://localhost:5600/api/crons?t=$currentTimeStamp" \
-X 'PUT' \
-H "Accept: application/json" \
-H "Authorization: Bearer $token" \
-H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36" \
-H "Content-Type: application/json;charset=UTF-8" \
-H "Origin: http://localhost:5700" \
-H "Referer: http://localhost:5700/crontab" \
-H "Accept-Language: en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7" \
--data-raw "{\"command\":\"$command\",\"_id\":\"$id\"}" \
--compressed
)
code=$(echo $api | jq -r .code)
message=$(echo $api | jq -r .message)
if [[ $code == 200 ]]; then
echo -e "$name -> 更新成功"
else
echo -e "$name -> 更新失败(${message})"
fi
}

del_cron_api() {
local ids=$1
local currentTimeStamp=$(date +%s)
Expand Down
4 changes: 3 additions & 1 deletion shell/bot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ fi
echo -e "\nbot文件下载成功...\n"

echo -e "3、安装python3依赖...\n"
pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
if [[ $PipMirror ]]; then
pip3 config set global.index-url $PipMirror
fi
cp -f "$repo_path/jbot/requirements.txt" "$dir_root"
pip3 --default-timeout=100 install -r requirements.txt --no-cache-dir
echo -e "\npython3依赖安装成功...\n"
Expand Down
10 changes: 7 additions & 3 deletions shell/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,14 @@ gen_list_repo() {
fi
for file in ${files}; do
filename=$(basename $file)
cp -f $file $dir_scripts/${author}_${filename}
echo ${author}_${filename} >>"$dir_list_tmp/${repo}_scripts.list"
cp -f $file $dir_scripts/${repo}_${filename}
echo ${repo}_${filename} >>"$dir_list_tmp/${repo}_scripts.list"
cron_id=$(grep -E "$cmd_task ${author}_${filename}" $list_crontab_user | perl -pe "s|.*ID=(.*) $cmd_task ${author}_${filename}\.*|\1|")
if [[ $cron_id ]]; then
result=$(update_cron_command_api "$cmd_task ${repo}_${filename}:$cron_id")
fi
done
grep -E "$cmd_task $author" $list_crontab_user | perl -pe "s|.*ID=(.*) $cmd_task ($author_.*)\.*|\2|" | awk -F " " '{print $1}' | sort -u >"$dir_list_tmp/${repo}_user.list"
grep -E "$cmd_task $repo" $list_crontab_user | perl -pe "s|.*ID=(.*) $cmd_task ($repo_.*)\.*|\2|" | awk -F " " '{print $1}' | sort -u >"$dir_list_tmp/${repo}_user.list"
cd $dir_current
}

Expand Down
2 changes: 2 additions & 0 deletions src/pages/crontab/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,8 @@ const Crontab = () => {
hideOnSinglePage: true,
showSizeChanger: true,
defaultPageSize: 20,
showTotal: (total: number, range: number[]) =>
`第 ${range[0]}-${range[1]} 条/总共 ${total} 条`,
}}
dataSource={value}
rowKey="_id"
Expand Down
17 changes: 14 additions & 3 deletions src/pages/crontab/logModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
Loading3QuartersOutlined,
CheckCircleOutlined,
} from '@ant-design/icons';
import { Controlled as CodeMirror } from 'react-codemirror2';

enum CrontabStatus {
'running',
Expand Down Expand Up @@ -98,9 +99,19 @@ const CronLogModal = ({
onOk={() => cancel()}
onCancel={() => cancel()}
>
<pre style={{ whiteSpace: 'pre-wrap', wordWrap: 'break-word' }}>
{!loading && value}
</pre>
{!loading && value && (
<CodeMirror
value={value}
options={{
lineWrapping: true,
readOnly: true,
}}
onBeforeChange={(editor, data, value) => {
setValue(value);
}}
onChange={(editor, data, value) => {}}
/>
)}
</Modal>
);
};
Expand Down

0 comments on commit 583fe05

Please sign in to comment.