Revision 57216
Added by Ioannis Diplas over 4 years ago
CompatibilityTestListener.java | ||
---|---|---|
13 | 13 |
import eu.dnetlib.validator.engine.execution.CompletedTask; |
14 | 14 |
import eu.dnetlib.validator.engine.execution.JobListener; |
15 | 15 |
|
16 |
public class CompatibilityTestListener implements JobListener{
|
|
16 |
public class CompatibilityTestListener extends AbstractValidatorListener{
|
|
17 | 17 |
private static Logger logger = Logger.getLogger(CompatibilityTestListener.class); |
18 | 18 |
|
19 | 19 |
private Emailer emailer = null; |
20 | 20 |
private String valBaseUrl = null; |
21 | 21 |
private String validationSet = null; |
22 | 22 |
private String guidelines = null; |
23 |
private JobsDAO jobsDao; |
|
24 |
|
|
25 |
private int totalJobs; |
|
26 |
private int jobsFinished = 0; |
|
27 | 23 |
|
28 | 24 |
@Override |
29 |
@Transactional(propagation = Propagation.REQUIRED) |
|
30 |
public synchronized void finished(int jobId, Map<String, Object> jobContext) { |
|
31 |
try { |
|
32 |
jobsFinished++; |
|
33 |
if (jobsFinished == totalJobs) { |
|
34 |
logger.debug("all jobs finished"); |
|
35 |
jobsDao.setTotalJobFinished(jobId, null, false); |
|
36 |
this.sendMail((Integer) jobContext.get("jobSubmittedId"), (String) jobContext.get("jobSubmittedUser")); |
|
37 |
} else { |
|
38 |
logger.debug("not all jobs finished yet. Waiting "+ (totalJobs-jobsFinished) + " job(s) to finish" ); |
|
39 |
} |
|
40 |
} catch (Exception e) { |
|
41 |
logger.error("Error while finalizing successfull compatibility test job", e); |
|
42 |
} |
|
25 |
protected void jobSuccess(int jobId, Map<String, Object> jobContext) { |
|
26 |
sendMail(jobId, (String) jobContext.get("jobSubmittedUser")); |
|
43 | 27 |
} |
44 | 28 |
|
45 | 29 |
@Override |
46 |
@Transactional(propagation = Propagation.REQUIRED) |
|
47 |
public synchronized void failed(int jobId, Map<String, Object> jobContext, Throwable t) { |
|
48 |
try { |
|
49 |
jobsFinished++; |
|
50 |
if (jobsFinished == totalJobs) { |
|
51 |
jobsDao.setTotalJobFinished(jobId, t.getMessage(), true); |
|
52 |
this.sendMail((Integer) jobContext.get("jobSubmittedId"), (String) jobContext.get("jobSubmittedUser")); |
|
53 |
} else { |
|
54 |
logger.debug("not all jobs finished yet. Waiting "+ (totalJobs-jobsFinished) + " job(s) to finish" ); |
|
55 |
} |
|
56 |
} catch (Exception e) { |
|
57 |
logger.error("Error while finalizing failed compatibility test job", e); |
|
58 |
} |
|
30 |
protected void jobFailure(int jobId, Map<String, Object> jobContext, Throwable t) { |
|
31 |
sendMail( jobId, (String) jobContext.get("jobSubmittedUser")); |
|
59 | 32 |
} |
60 | 33 |
|
61 |
|
|
62 |
|
|
63 | 34 |
private void sendMail(int jobSubmittedId, String jobSubmittedUser) { |
64 | 35 |
logger.debug("JOBID:"+jobSubmittedId+"# Sending email for finished job"); |
65 | 36 |
String mailTo = jobSubmittedUser; |
... | ... | |
78 | 49 |
logger.error("JOBID:"+jobSubmittedId+"# Error sending email for finished job", e); |
79 | 50 |
} |
80 | 51 |
} |
81 |
|
|
82 |
@Override |
|
83 |
public void currentResults(List<CompletedTask> tasks, int jobId, |
|
84 |
Object object, Map<String, Object> recordContext, Throwable t) { |
|
85 |
// TODO Auto-generated method stub |
|
86 |
|
|
87 |
} |
|
88 | 52 |
|
89 |
@Override |
|
90 |
public void currentResults(List<CompletedTask> tasks, int jobId, |
|
91 |
Object object, Map<String, Object> recordContext) { |
|
92 |
// TODO Auto-generated method stub |
|
93 |
|
|
94 |
} |
|
95 |
|
|
96 | 53 |
public String getValBaseUrl() { |
97 | 54 |
return valBaseUrl; |
98 | 55 |
} |
... | ... | |
125 | 82 |
this.guidelines = guidelines; |
126 | 83 |
} |
127 | 84 |
|
128 |
public int getTotalJobs() { |
|
129 |
return totalJobs; |
|
130 |
} |
|
131 |
|
|
132 |
public void setTotalJobs(int totalJobs) { |
|
133 |
this.totalJobs = totalJobs; |
|
134 |
} |
|
135 |
|
|
136 |
public JobsDAO getJobsDao() { |
|
137 |
return jobsDao; |
|
138 |
} |
|
139 |
|
|
140 |
public void setJobsDao(JobsDAO jobsDao) { |
|
141 |
this.jobsDao = jobsDao; |
|
142 |
} |
|
143 |
|
|
144 |
|
|
145 | 85 |
} |
Also available in: Unified diff
Splitting some listeners and adding getJobSummary methods