Commit eae6585f by ys

项目初始化

parent 7fd38335
......@@ -107,6 +107,7 @@ public class XxlJobAdminClient {
}
}
/**
* 立即执行一次任务
*/
......@@ -121,6 +122,51 @@ public class XxlJobAdminClient {
}
}
public void start(int jobId) {
FormBody formBody = new FormBody.Builder()
.add("id", String.valueOf(jobId))
.build();
try {
postForm("jobinfo/start", formBody, null);
} catch (Exception e) {
}
}
public void stop(int jobId) {
FormBody formBody = new FormBody.Builder()
.add("id", String.valueOf(jobId))
.build();
try {
postForm("jobinfo/stop", formBody, null);
} catch (Exception e) {
}
}
public Integer getExecutorIdByName(String name) {
FormBody formBody = new FormBody.Builder()
.add("appname", name)
.add("start", "0")
.add("length", "10")
.build();
try {
return (Integer) postForm("jobgroup/pageList", formBody, (response, list) -> {
ResponseBody responseBody = response.body();
if (responseBody != null) {
PageResult result = objectMapper.readValue(responseBody.string(), PageResult.class);
List<Object> data = result.getData();
if (data == null || data.isEmpty()) {
list.add(null);
return;
}
Integer id = (Integer) ((Map<String, Object>) data.get(0)).get("id");
list.add(id);
}
}).get(0);
} catch (Exception e) {
return null;
}
}
public List<TriggerLog> getTriggerLogs(int jobId, String from, String to, int offset, int limit) {
return doGetTriggerLogs(jobId, -1, from, to, offset, limit);
}
......
......@@ -38,4 +38,9 @@ class XxlJobAdminClientTest {
2);
triggerLogs.forEach(log -> System.out.println(log.getTriggerId() + ": " + log.getTriggerMsg()));
}
@Test
void getExecutorIdByName() {
System.out.println(adminClient.getExecutorIdByName("sample-executor"));
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment