mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-18 23:43:06 +00:00
Merge branch 'w2p-116609_improve-running-process-observability' into w2p-116609_improve-running-process-observability-main
Conflicts: dspace-api/src/main/java/org/dspace/scripts/ProcessServiceImpl.java
This commit is contained in:
@@ -47,13 +47,12 @@ import org.dspace.eperson.EPerson;
|
||||
import org.dspace.eperson.Group;
|
||||
import org.dspace.scripts.service.ProcessService;
|
||||
import org.dspace.services.ConfigurationService;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* The implementation for the {@link ProcessService} class
|
||||
*/
|
||||
public class ProcessServiceImpl implements ProcessService, InitializingBean {
|
||||
public class ProcessServiceImpl implements ProcessService {
|
||||
|
||||
private static final Logger log = org.apache.logging.log4j.LogManager.getLogger(ProcessService.class);
|
||||
|
||||
@@ -75,33 +74,6 @@ public class ProcessServiceImpl implements ProcessService, InitializingBean {
|
||||
@Autowired
|
||||
private ConfigurationService configurationService;
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
try {
|
||||
Context context = new Context();
|
||||
|
||||
// Processes that were running or scheduled when tomcat crashed, should be cleaned up during startup.
|
||||
List<Process> processesToBeFailed = findByStatusAndCreationTimeOlderThan(
|
||||
context, List.of(ProcessStatus.RUNNING, ProcessStatus.SCHEDULED), new Date());
|
||||
for (Process process : processesToBeFailed) {
|
||||
context.setCurrentUser(process.getEPerson());
|
||||
// Fail the process.
|
||||
log.info("Process with ID {} did not complete before tomcat shutdown, failing it now.",
|
||||
process.getID());
|
||||
fail(context, process);
|
||||
// But still attach its log to the process.
|
||||
appendLog(process.getID(), process.getName(),
|
||||
"Process did not complete before tomcat shutdown.",
|
||||
ProcessLogLevel.ERROR);
|
||||
createLogBitstream(context, process);
|
||||
}
|
||||
|
||||
context.complete();
|
||||
} catch (Exception e) {
|
||||
log.error("Unable to clean up Processes: ", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Process create(Context context, EPerson ePerson, String scriptName,
|
||||
List<DSpaceCommandLineParameter> parameters,
|
||||
@@ -359,6 +331,23 @@ public class ProcessServiceImpl implements ProcessService, InitializingBean {
|
||||
return processDAO.countByUser(context, user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failRunningProcesses(Context context) throws SQLException, IOException, AuthorizeException {
|
||||
List<Process> processesToBeFailed = findByStatusAndCreationTimeOlderThan(
|
||||
context, List.of(ProcessStatus.RUNNING, ProcessStatus.SCHEDULED), new Date());
|
||||
for (Process process : processesToBeFailed) {
|
||||
context.setCurrentUser(process.getEPerson());
|
||||
// Fail the process.
|
||||
log.info("Process with ID {} did not complete before tomcat shutdown, failing it now.", process.getID());
|
||||
fail(context, process);
|
||||
// But still attach its log to the process.
|
||||
appendLog(process.getID(), process.getName(),
|
||||
"Process did not complete before tomcat shutdown.",
|
||||
ProcessLogLevel.ERROR);
|
||||
createLogBitstream(context, process);
|
||||
}
|
||||
}
|
||||
|
||||
private String formatLogLine(int processId, String scriptName, String output, ProcessLogLevel processLogLevel) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
Reference in New Issue
Block a user