*/
private void runWFRecovery() {
XLog.Info.get().clear();
XLog log = XLog.getLog(getClass());
// queue command for action recovery
WorkflowStore store = null;
try {
store = Services.get().get(StoreService.class).getStore(WorkflowStore.class);
store.beginTrx();
List<WorkflowActionBean> actions = null;
try {
actions = store.getPendingActions(olderThan);
}
catch (StoreException ex) {
log.warn("Exception while reading pending actions from storage", ex);
}
//log.debug("QUEUING[{0}] pending wf actions for potential recovery", actions.size());
msg.append(" WF_ACTIONS " + actions.size());
for (WorkflowActionBean action : actions) {
Services.get().get(InstrumentationService.class).get().incr(INSTRUMENTATION_GROUP,
INSTR_RECOVERED_ACTIONS_COUNTER, 1);
if (action.getStatus() == WorkflowActionBean.Status.PREP
|| action.getStatus() == WorkflowActionBean.Status.START_MANUAL) {
queueCallable(new ActionStartCommand(action.getId(), action.getType()));
}
else {
if (action.getStatus() == WorkflowActionBean.Status.START_RETRY) {
Date nextRunTime = action.getPendingAge();
queueCallable(new ActionStartCommand(action.getId(), action.getType()), nextRunTime.getTime()
- System.currentTimeMillis());
}
else {
if (action.getStatus() == WorkflowActionBean.Status.DONE
|| action.getStatus() == WorkflowActionBean.Status.END_MANUAL) {
queueCallable(new ActionEndCommand(action.getId(), action.getType()));
}
else {
if (action.getStatus() == WorkflowActionBean.Status.END_RETRY) {
Date nextRunTime = action.getPendingAge();
queueCallable(new ActionEndCommand(action.getId(), action.getType()), nextRunTime.getTime()
- System.currentTimeMillis());
}
else {
if (action.getStatus() == WorkflowActionBean.Status.OK
|| action.getStatus() == WorkflowActionBean.Status.ERROR) {
queueCallable(new SignalCommand(action.getJobId(), action.getId()));
}
}
}
}
}
}
store.commitTrx();
}
catch (StoreException ex) {
if (store != null) {
store.rollbackTrx();
}
log.warn("Exception while getting store to get pending actions", ex);
}
catch (Exception ex) {
log.error("Exception, {0}", ex.getMessage(), ex);
if (store != null && store.isActive()) {
try {
store.rollbackTrx();
}
catch (RuntimeException rex) {
log.warn("openjpa error, {0}", rex.getMessage(), rex);
}
}
}
finally {
if (store != null) {
if (!store.isActive()) {
try {
store.closeTrx();
}
catch (RuntimeException rex) {
log.warn("Exception while attempting to close store", rex);
}
}