BigRisingTask.java 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package com.gyee.impala.service.task;
  2. import com.gyee.impala.common.config.GyeeConfig;
  3. import com.gyee.impala.common.util.JudeSystem;
  4. import com.gyee.impala.model.master.Casefaultalg;
  5. import com.gyee.impala.service.master.CasefaultalgService;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.scheduling.annotation.EnableScheduling;
  8. import org.springframework.scheduling.annotation.Scheduled;
  9. import org.springframework.stereotype.Service;
  10. import java.io.BufferedReader;
  11. import java.io.IOException;
  12. import java.io.InputStreamReader;
  13. import java.util.List;
  14. @Service
  15. @EnableScheduling
  16. public class BigRisingTask {
  17. @Autowired
  18. private CasefaultalgService casefaultalgService;
  19. /**
  20. * 保存脚本的位置
  21. */
  22. @Autowired
  23. private GyeeConfig gyeeConfig;
  24. @Scheduled(cron = "0 0/10 * * * ?")
  25. // @Scheduled(fixedRate=1000)
  26. private void getBigRisingTasks() {
  27. List<Casefaultalg> list = casefaultalgService.getListRemarkIsNull();
  28. System.out.println(list.size());
  29. list.stream().forEach(l->{
  30. System.out.println(l.getId()+"|"+l.getRemark());
  31. try {
  32. //组装调用脚本命令
  33. String name = "grad";
  34. String cmdPath = gyeeConfig.getDiagnosePath();
  35. String inst = JudeSystem.isWindows() ? "cmd" : "/bin/sh";
  36. String c = JudeSystem.isWindows() ? "/c" : "-c";
  37. String[] cmd = {inst, c, "python " + cmdPath + name + ".py " + l.getId()};
  38. Process p;
  39. System.out.println(cmd[0] + " " + cmd[1] + " " + cmd[2]);
  40. //执行脚本
  41. p = Runtime.getRuntime().exec(cmd);
  42. p.waitFor();
  43. Thread.sleep(100);
  44. } catch (IOException e) {
  45. e.printStackTrace();
  46. } catch (InterruptedException e) {
  47. e.printStackTrace();
  48. }finally {
  49. }
  50. });
  51. }
  52. }