@@ -65,7 +65,32 @@ public abstract class AbstractJobCommand extends AbstractCallableCommand {
65
65
private PlatformTransactionManager transactionManager ;
66
66
private JobLauncher jobLauncher ;
67
67
68
- private TaskExecutorJobLauncher taskExecutorJobLauncher () throws Exception {
68
+ @ Override
69
+ protected void initialize () throws RiotInitializationException {
70
+ super .initialize ();
71
+ if (jobName == null ) {
72
+ jobName = jobName ();
73
+ }
74
+ if (jobRepository == null ) {
75
+ try {
76
+ jobRepository = JobUtils .jobRepositoryFactoryBean (jobRepositoryName ).getObject ();
77
+ } catch (Exception e ) {
78
+ throw new RiotInitializationException ("Could not create job repository" , e );
79
+ }
80
+ }
81
+ if (transactionManager == null ) {
82
+ transactionManager = JobUtils .resourcelessTransactionManager ();
83
+ }
84
+ if (jobLauncher == null ) {
85
+ try {
86
+ jobLauncher = jobLauncher ();
87
+ } catch (Exception e ) {
88
+ throw new RiotInitializationException ("Could not create job launcher" , e );
89
+ }
90
+ }
91
+ }
92
+
93
+ private JobLauncher jobLauncher () throws Exception {
69
94
TaskExecutorJobLauncher launcher = new TaskExecutorJobLauncher ();
70
95
launcher .setJobRepository (jobRepository );
71
96
launcher .setTaskExecutor (new SyncTaskExecutor ());
@@ -82,26 +107,20 @@ private JobBuilder jobBuilder() {
82
107
}
83
108
84
109
@ Override
85
- protected void execute () throws Exception {
86
- if (jobName == null ) {
87
- jobName = jobName ();
88
- }
89
- if (jobRepository == null ) {
90
- jobRepository = JobUtils .jobRepositoryFactoryBean (jobRepositoryName ).getObject ();
91
- }
92
- if (transactionManager == null ) {
93
- transactionManager = JobUtils .resourcelessTransactionManager ();
94
- }
95
- if (jobLauncher == null ) {
96
- jobLauncher = taskExecutorJobLauncher ();
110
+ protected void execute () throws RiotExecutionException {
111
+ Job job = job ();
112
+ JobExecution jobExecution ;
113
+ try {
114
+ jobExecution = jobLauncher .run (job , new JobParameters ());
115
+ } catch (JobExecutionException e ) {
116
+ throw new RiotExecutionException ("Could not run job " + job .getName (), e );
97
117
}
98
- JobExecution jobExecution = jobLauncher .run (job (), new JobParameters ());
99
118
if (JobUtils .isFailed (jobExecution .getExitStatus ())) {
100
119
for (StepExecution stepExecution : jobExecution .getStepExecutions ()) {
101
120
ExitStatus stepExitStatus = stepExecution .getExitStatus ();
102
121
if (JobUtils .isFailed (stepExitStatus )) {
103
122
if (CollectionUtils .isEmpty (stepExecution .getFailureExceptions ())) {
104
- throw new JobExecutionException (stepExitStatus .getExitDescription ());
123
+ throw new RiotExecutionException (stepExitStatus .getExitDescription ());
105
124
}
106
125
throw wrapException (stepExecution .getFailureExceptions ());
107
126
}
@@ -117,11 +136,11 @@ private String jobName() {
117
136
return commandSpec .name ();
118
137
}
119
138
120
- private JobExecutionException wrapException (List <Throwable > throwables ) {
139
+ private RiotExecutionException wrapException (List <Throwable > throwables ) {
121
140
if (throwables .isEmpty ()) {
122
- return new JobExecutionException ("Job failed" );
141
+ return new RiotExecutionException ("Job failed" );
123
142
}
124
- return new JobExecutionException ("Job failed" , throwables .get (0 ));
143
+ return new RiotExecutionException ("Job failed" , throwables .get (0 ));
125
144
}
126
145
127
146
protected Job job (Step <?, ?>... steps ) {
0 commit comments