|
@@ -13,7 +13,9 @@ import com.winhc.dataworks.flow.touch.service.TouchService;
|
|
|
import com.winhc.dataworks.flow.touch.utils.DingUtils;
|
|
|
import lombok.SneakyThrows;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.cli.*;
|
|
|
|
|
|
+import java.io.FileNotFoundException;
|
|
|
import java.time.Duration;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
@@ -29,26 +31,85 @@ import java.util.stream.Collectors;
|
|
|
public class Main {
|
|
|
@Autowired
|
|
|
private TouchService touchService;
|
|
|
+ private static final Options options = new Options();
|
|
|
+
|
|
|
|
|
|
@Autowired
|
|
|
private DingUtils dingUtils;
|
|
|
|
|
|
+ static {
|
|
|
+ options.addOption("s", "singleJob", false, "选填,是否单独触发一个业务流程");
|
|
|
+ options.addOption("b", "bizDate", true, "必填,业务时间");
|
|
|
+ options.addOption("f", "fileName", true, "必填,yaml文件");
|
|
|
|
|
|
- public static void main(String[] args) {
|
|
|
- if (args.length != 1) {
|
|
|
- System.out.println("请输入调度的 bizDate");
|
|
|
- System.exit(-9999);
|
|
|
+ options.addOption("flow", "flow", true, "单任务必填,业务流程名");
|
|
|
+ options.addOption("task", "taskName", true, "单任务必填,任务名");
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void verify(CommandLine commandLine) {
|
|
|
+ try {
|
|
|
+ if (!commandLine.hasOption("b") || !commandLine.hasOption("f")) {
|
|
|
+ throw new RuntimeException();
|
|
|
+ }
|
|
|
+ if (commandLine.hasOption("s")) {
|
|
|
+ if (!commandLine.hasOption("flow") || !commandLine.hasOption("task")) {
|
|
|
+ throw new RuntimeException();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ HelpFormatter formatter = new HelpFormatter();
|
|
|
+ formatter.printHelp("很棒,参数错误", options);
|
|
|
+ System.exit(-1);
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
LightDiContext context = LightDi.initContextByPackage(Main.class.getPackage().getName());
|
|
|
- Main bean = context.getBean(Main.class);
|
|
|
- bean.start(args[0]);
|
|
|
+ DingUtils dd = context.getBean(DingUtils.class);
|
|
|
+ CommandLineParser parser = new DefaultParser();
|
|
|
+ try {
|
|
|
+ CommandLine commandLine = parser.parse(options, args);
|
|
|
+ verify(commandLine);
|
|
|
+ String bizDate = commandLine.getOptionValue("b");
|
|
|
+ String fileName = commandLine.getOptionValue("f");
|
|
|
+ List<DataWorksFlowJob> jobs = SchemaInit.getJobs(fileName);
|
|
|
+
|
|
|
+ if (commandLine.hasOption("s")) {
|
|
|
+ log.info("执行单个业务流程!");
|
|
|
+ String flow = commandLine.getOptionValue("flow");
|
|
|
+ String task = commandLine.getOptionValue("task");
|
|
|
+ SingleJobMain singleJobMain = context.getBean(SingleJobMain.class);
|
|
|
+ String msg = "开始执行单个业务流程!bizDate:" + bizDate + " flow:" + flow + " task:" + task + " JobFile:" + commandLine.getOptionValue("f");
|
|
|
+// dd.send(msg);
|
|
|
+ log.info(msg);
|
|
|
+ singleJobMain.start(flow, task, bizDate, jobs);
|
|
|
+ } else {
|
|
|
+ log.info("触发全部业务流程!");
|
|
|
+ Main bean = context.getBean(Main.class);
|
|
|
+ String msg = "开始执行全部业务流程!bizDate:" + bizDate + " JobFile:" + commandLine.getOptionValue("f");
|
|
|
+ dd.send(msg);
|
|
|
+ log.info(msg);
|
|
|
+ bean.start(bizDate, jobs);
|
|
|
+ }
|
|
|
+ } catch (ParseException e) {
|
|
|
+ HelpFormatter formatter = new HelpFormatter();
|
|
|
+ formatter.printHelp("很棒,参数错误", options);
|
|
|
+ System.exit(-1);
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
+ System.exit(-2);
|
|
|
+ } catch (Exception e) {
|
|
|
+ dd.send(e.getMessage());
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ System.exit(-3);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@SneakyThrows
|
|
|
- private void start(String bizDate) {
|
|
|
- log.info("start");
|
|
|
+ private void start(String bizDate, List<DataWorksFlowJob> jobs) {
|
|
|
+ log.info("start!");
|
|
|
LocalDateTime start = LocalDateTime.now();
|
|
|
- List<DataWorksFlowJob> jobs = SchemaInit.LIST;
|
|
|
List<TaskInfo> collect = jobs.stream()
|
|
|
.flatMap(dataWorksFlowJob -> {
|
|
|
List<DataWorksFlowTask> task = dataWorksFlowJob.getTask();
|