Skip to content

Commit

Permalink
feat: 优化gst
Browse files Browse the repository at this point in the history
  • Loading branch information
苏文雄 committed Oct 18, 2019
1 parent 4cde74b commit 060b1d8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions exts/yapi-plugin-swagger-auto-sync/interfaceSyncUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class syncUtils {
* @param {*} uid 用户id
*/
async addSyncJob(projectId, cronExpression, swaggerUrl, syncMode, uid) {
if(!swaggerUrl)return;
let projectToken = await this.getProjectToken(projectId, uid);
//立即执行一次
this.syncInterface(projectId, swaggerUrl, syncMode, uid, projectToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export default class ProjectInterfaceSync extends Component {
};

validSwaggerUrl = async (rule, value, callback) => {
if(!value)return;
try{
await this.props.handleSwaggerUrlData(value);
} catch(e) {
Expand All @@ -99,7 +100,7 @@ export default class ProjectInterfaceSync extends Component {
});
//默认每份钟同步一次,取一个随机数
this.setState({
random_corn: Math.round(Math.random()*60) + ' * * * * *'
random_corn: '*/2 * * * *'
});
this.getSyncData();
}
Expand All @@ -125,6 +126,15 @@ export default class ProjectInterfaceSync extends Component {
});
};

sync_cronCheck(rule, value, callback){
if(!value)return;
value = value.trim();
if(value.split(/ +/).length > 5){
callback('不支持秒级别的设置,建议使用 "*/10 * * * *" ,每隔10分钟更新')
}
callback()
}

render() {
const { getFieldDecorator } = this.props.form;
return (
Expand Down Expand Up @@ -202,12 +212,15 @@ export default class ProjectInterfaceSync extends Component {
})(<Input />)}
</FormItem>

<FormItem {...formItemLayout} label={<span>类cron风格表达式(默认每分钟更新一次)&nbsp;<a href="https://blog.csdn.net/shouldnotappearcalm/article/details/89469047">参考</a></span>}>
<FormItem {...formItemLayout} label={<span>类cron风格表达式(默认10分钟更新一次)&nbsp;<a href="https://blog.csdn.net/shouldnotappearcalm/article/details/89469047">参考</a></span>}>
{getFieldDecorator('sync_cron', {
rules: [
{
required: true,
message: '输入node-schedule的类cron表达式!'
},
{
validator: this.sync_cronCheck
}
],
initialValue: this.state.sync_data.sync_cron ? this.state.sync_data.sync_cron : this.state.random_corn
Expand Down

0 comments on commit 060b1d8

Please sign in to comment.