java AWS lambda在不使用调度程序的情况下从请求处理程序运行Spring批处理作业
我的应用程序正在批处理中使用spring boot,并在aws lambda中进行测试。我希望在main方法中运行作业,而不是通过调度器。有可能吗
@SpringBootApplication
@EnableAutoConfiguration
@EnableJpaRepositories("com.myrepo.repository")
@ComponentScan("com.myrepo")
@EnableScheduling
public class Main {
private static final Logger LOG = LoggerFactory.getLogger(hMain.class);
@Autowired
JobLauncher launcher;
@Autowired
Job job;
public static void main(String[] args) {
try {
LOG.info("Start of application - debt card notofication JOB");
SpringApplication.run(BatchMain.class, args);
} catch (Exception e) {
LOG.error("Exception caught bathch Main, );
}
}
}
编辑——我写了下面的代码,但它在aws lambda函数中不起作用
@Scheduled(cron = "0/1 * * * * *")
public void performBatchOpertaion() {
try {
LOG.info("Scheduling Job and Launcher {}, {}", job, launcher);
JobParameters params = new JobParametersBuilder()
.addString(Constants.MYBATCH, String.valueOf(System.currentTimeMillis()))
.toJobParameters();
launcher.run(job, params);
} catch (Exception e) {
LOG.error("Unable to schedules ", e.getCause());
}
}
public static void startApp() {
LOG.info("start batch job ");
SpringApplication.run(Main.class);
LOG.info("end batch job ");
}
下面是我的请求处理程序类,它调用Main类的statApp()
--------------------------------------------------------
public class MyHandler implements RequestHandler<Map<String, Object>, String> {
private static final Logger LOG = LoggerFactory.getLogger(MyHandler.class);
@Autowired
BatchMain main;
@Override
public String handleRequest(Map<String, Object> input, Context context) {
LOG.info("Inside the handler request");
BatchMain.startApp();
LOG.info("End of handler request");
return "End Of Application";
}
}
共 (0) 个答案