public FileImport() { setLastUpdatedUUID(" "); setErrorMessage(" "); setState(FileImport.State.CREATED); }
fileImport.setState( state ); fileImport.setErrorMessage( message );
@Override protected void doJob(JobExecution jobExecution) throws Exception { logger.info("execute FileImportJob {}", jobExecution.toString()); try { JobData jobData = jobExecution.getJobData(); if (jobData == null) { logger.error("jobData cannot be null"); return; } // heartbeat to indicate job has started jobExecution.heartbeat(); // call the File Parser for the file set in job execution importService.downloadAndImportFile(jobExecution); } catch ( Throwable t ) { logger.debug("Error importing file", t); // update file import record UUID fileImportId = (UUID) jobExecution.getJobData().getProperty(FILE_IMPORT_ID); EntityManager em = emf.getEntityManager(emf.getManagementAppId()); FileImport fileImport = em.get(fileImportId, FileImport.class); fileImport.setState( FileImport.State.FAILED ); em.update( fileImport ); throw t; } logger.info("File Import Service completed job: {}", jobExecution.getJobName() ); }
/** * This method is called when the job is retried maximum times by the scheduler but still fails. * Thus the scheduler marks it as DEAD. */ @Override public void dead( final JobExecution execution ) throws Exception { // Get the root entity manager EntityManager rootEm = emf.getEntityManager( emf.getManagementAppId() ); // Mark the sub-job i.e. File Import Job as Failed FileImport fileImport = null;//importService.getFileImportEntity(execution); fileImport.setErrorMessage("The Job has been tried maximum times but still failed"); fileImport.setState(FileImport.State.FAILED); rootEm.update(fileImport); // If one file Job fails, mark the main import Job also as failed Results ImportJobResults = rootEm.getSourceEntities( fileImport, "includes", null, Level.ALL_PROPERTIES); List<Entity> importEntity = ImportJobResults.getEntities(); UUID importId = importEntity.get(0).getUuid(); Import importUG = rootEm.get(importId, Import.class); importUG.setState(Import.State.FAILED); rootEm.update(importUG); } }
fileImport.setState(FileImport.State.STARTED); rootEM.update(fileImport);