use of cn.hutool.cron.pattern.CronPattern in project hutool by dromara.
the class TaskTableTest method toStringTest.
@Test
@Ignore
public void toStringTest() {
final TaskTable taskTable = new TaskTable();
taskTable.add(IdUtil.fastUUID(), new CronPattern("*/10 * * * * *"), () -> Console.log("Task 1"));
taskTable.add(IdUtil.fastUUID(), new CronPattern("*/20 * * * * *"), () -> Console.log("Task 2"));
taskTable.add(IdUtil.fastUUID(), new CronPattern("*/30 * * * * *"), () -> Console.log("Task 3"));
Console.log(taskTable);
}
use of cn.hutool.cron.pattern.CronPattern in project Jpom by dromara.
the class ScriptController method save.
@RequestMapping(value = "save.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public String save(NodeScriptModel nodeScriptModel, String type) {
Assert.notNull(nodeScriptModel, "没有数据");
Assert.hasText(nodeScriptModel.getContext(), "内容为空");
//
String autoExecCron = nodeScriptModel.getAutoExecCron();
if (StrUtil.isNotEmpty(autoExecCron)) {
try {
new CronPattern(autoExecCron);
} catch (Exception e) {
throw new IllegalArgumentException("定时执行表达式格式不正确");
}
}
nodeScriptModel.setWorkspaceId(getWorkspaceId());
//
nodeScriptModel.setContext(HtmlUtil.unescape(nodeScriptModel.getContext()));
NodeScriptModel eModel = nodeScriptServer.getItem(nodeScriptModel.getId());
boolean needCreate = false;
if ("add".equalsIgnoreCase(type)) {
Assert.isNull(eModel, "id已经存在啦");
nodeScriptModel.setId(IdUtil.fastSimpleUUID());
File file = nodeScriptModel.getFile(true);
if (file.exists() || file.isDirectory()) {
return JsonMessage.getString(405, "当地id路径文件已经存在来,请修改");
}
nodeScriptServer.addItem(nodeScriptModel);
return JsonMessage.getString(200, "添加成功");
} else if ("sync".equalsIgnoreCase(type)) {
if (eModel == null) {
eModel = new NodeScriptModel();
eModel.setId(nodeScriptModel.getId());
needCreate = true;
}
eModel.setScriptType("server-sync");
}
Assert.notNull(eModel, "对应数据不存在");
eModel.setName(nodeScriptModel.getName());
eModel.setAutoExecCron(autoExecCron);
eModel.setDescription(nodeScriptModel.getDescription());
eModel.setContext(nodeScriptModel.getContext());
eModel.setDefArgs(nodeScriptModel.getDefArgs());
if (needCreate) {
nodeScriptServer.addItem(eModel);
} else {
nodeScriptServer.updateItem(eModel);
}
return JsonMessage.getString(200, "修改成功");
}
use of cn.hutool.cron.pattern.CronPattern in project Jpom by dromara.
the class CommandInfoController method edit.
/**
* 新建/编辑命令
*
* @param data 命令信息
* @return result
*
* @api {POST} node/ssh_command/edit 新建/编辑命令
* @apiGroup node/ssh_command
* @apiUse defResultJson
* @apiBody {String} name 命令名称
* @apiBody {String} command 命令内容
* @apiBody {String} [desc] 命令描述
* @apiBody {String} defParams 默认参数
* @apiBody {String} autoExecCron 定时构建表达式
* @apiBody {String} id 命令主键 ID
* @apiBody {String} [sshIds] SSH 节点
*/
@RequestMapping(value = "edit", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.EDIT)
public String edit(@RequestBody JSONObject data) {
String name = data.getString("name");
String command = data.getString("command");
String desc = data.getString("desc");
String defParams = data.getString("defParams");
Assert.hasText(name, "请输入命令名称");
Assert.hasText(command, "请输入命令内容");
String autoExecCron = data.getString("autoExecCron");
String id = data.getString("id");
//
CommandModel commandModel = new CommandModel();
commandModel.setName(name);
commandModel.setCommand(command);
commandModel.setDesc(desc);
commandModel.setSshIds(data.getString("sshIds"));
if (StrUtil.isNotEmpty(autoExecCron)) {
try {
new CronPattern(autoExecCron);
} catch (Exception e) {
throw new IllegalArgumentException("定时构建表达式格式不正确");
}
}
commandModel.setAutoExecCron(autoExecCron);
//
if (StrUtil.isNotEmpty(defParams)) {
List<CommandModel.CommandParam> params = CommandModel.params(defParams);
if (params == null) {
commandModel.setDefParams(StrUtil.EMPTY);
} else {
commandModel.setDefParams(JSONObject.toJSONString(params));
}
} else {
commandModel.setDefParams(StrUtil.EMPTY);
}
if (StrUtil.isEmpty(id)) {
commandService.insert(commandModel);
} else {
commandModel.setId(id);
commandService.updateById(commandModel, getRequest());
}
return JsonMessage.getString(200, "操作成功");
}
Aggregations