1
2
3
4
5
6 package org.tailormap.api.scheduling;
7
8 import java.lang.invoke.MethodHandles;
9 import org.quartz.DisallowConcurrentExecution;
10 import org.quartz.JobDataMap;
11 import org.quartz.JobDetail;
12 import org.quartz.JobExecutionContext;
13 import org.quartz.JobExecutionException;
14 import org.quartz.PersistJobDataAfterExecution;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17 import org.springframework.scheduling.quartz.QuartzJobBean;
18
19
20 @DisallowConcurrentExecution
21 @PersistJobDataAfterExecution
22 public class FailingPocTask extends QuartzJobBean implements Task {
23 private static final Logger logger =
24 LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
25 private String description;
26
27 @Override
28 protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
29 final JobDetail jobDetail = context.getJobDetail();
30
31
32 final JobDataMap jobDataMap = jobDetail.getJobDataMap();
33
34 try {
35
36 long workingTime = (long) (Math.random() * 10000);
37 logger.debug("Working for {} ms", workingTime);
38 Thread.sleep(workingTime);
39 throw new UnsupportedOperationException("Failing POC task failed.");
40 } catch (Exception e) {
41 logger.error("Failing POC task failed.", e);
42 jobDataMap.put(Task.LAST_RESULT_KEY, "POC task executed unsuccessfully");
43 context.setResult("POC task executed unsuccessfully");
44 throw new JobExecutionException(e);
45 }
46 }
47
48
49
50 @Override
51 public TaskType getType() {
52 return TaskType.FAILINGPOC;
53 }
54
55 @Override
56 public String getDescription() {
57 return description;
58 }
59
60 @Override
61 public void setDescription(String description) {
62 this.description = description;
63 }
64
65 }