1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.batch;
17
18 import java.util.List;
19
20 import org.apache.commons.lang.StringUtils;
21 import org.apache.log4j.Logger;
22 import org.kuali.hr.time.service.base.TkServiceLocator;
23 import org.kuali.hr.time.util.TKUtils;
24 import org.kuali.hr.time.util.TkConstants;
25
26
27
28
29 public class BatchJobEntryPoller extends Thread {
30 private static final Logger LOG = Logger.getLogger(BatchJobEntryPoller.class);
31
32 TkBatchManager manager;
33 int secondsToSleep;
34 int startupSleep;
35 String ipAddress;
36
37 public BatchJobEntryPoller(TkBatchManager manager, int sleepSeconds, int startupSleep) {
38 this.manager = manager;
39 this.secondsToSleep = sleepSeconds;
40 this.startupSleep = startupSleep;
41 this.ipAddress = TKUtils.getIPNumber();
42 }
43
44 @Override
45 public void run() {
46
47 try {
48 Thread.sleep(1000 * startupSleep);
49 } catch (Exception e) {
50 LOG.error(e);
51 }
52
53 while(true) {
54 LOG.debug("Looking for BatchJobEntries to run on '" + this.ipAddress + "'");
55 try {
56
57 List<BatchJobEntry> entries = TkServiceLocator.getBatchJobEntryService().getBatchJobEntries(ipAddress, TkConstants.BATCH_JOB_ENTRY_STATUS.SCHEDULED);
58
59
60 for (BatchJobEntry entry : entries) {
61 BatchJobEntryRunnable batchJobEntryRunnable = getRunnable(entry);
62 if (batchJobEntryRunnable != null) {
63 manager.pool.submit(batchJobEntryRunnable);
64 }
65 }
66 Thread.sleep(1000 * secondsToSleep);
67 } catch (Exception e) {
68 LOG.error(e);
69 }
70 }
71 }
72
73 private BatchJobEntryRunnable getRunnable(BatchJobEntry entry) {
74 BatchJobEntryRunnable bjer = null;
75
76 if (StringUtils.equals(entry.getBatchJobName(), TkConstants.BATCH_JOB_NAMES.APPROVE)) {
77 LOG.debug("Creating EmployeeApprovalBatchJobRunnable.");
78 bjer = new EmployeeApprovalBatchJobRunnable(entry);
79 } else if (StringUtils.equals(entry.getBatchJobName(), TkConstants.BATCH_JOB_NAMES.PAY_PERIOD_END)) {
80 LOG.debug("Creating PayPeriodEndBatchJobRunnable.");
81 bjer = new PayPeriodEndBatchJobRunnable(entry);
82 } else if (StringUtils.equals(entry.getBatchJobName(), TkConstants.BATCH_JOB_NAMES.SUPERVISOR_APPROVAL)) {
83 LOG.debug("Creating SupervisorApprovalBatchJobRunnable.");
84 bjer = new SupervisorApprovalBatchJobRunnable(entry);
85 } else if (StringUtils.equals(entry.getBatchJobName(), TkConstants.BATCH_JOB_NAMES.INITIATE)) {
86 LOG.debug("Creating InitiateBatchJobRunnable.");
87 bjer = new InitiateBatchJobRunnable(entry);
88 } else if(StringUtils.equals(entry.getBatchJobName(), TkConstants.BATCH_JOB_NAMES.BATCH_APPROVE_MISSED_PUNCH)) {
89 LOG.debug("BatchApproveMissedPunchJobRunnable is not run on a regular basis, skipping...");
90 } else {
91 LOG.warn("Unknown BatchJobEntryRunnable found in BatchJobEntry table. Unable to create Runnable.");
92 }
93
94 return bjer;
95 }
96
97 }