private void handleFilesForReprocessing(Connection dbConnection) {
			logger.info("Looking for files that are set to be reprocessed.");
			try {
				// first look for files that have the reprocess flag set and process_state as 1, and update their process_state and reset the flag
				// if the process state is 2 (error) but this has processed successfully before then the source file should not have been deleted so ok to reprocess
				PreparedStatement s = dbConnection.prepareStatement("UPDATE files SET process_state=3, reprocess=0 WHERE reprocess=1 AND (process_state=1 OR (process_state=2 AND has_processed_successfully=1))"+getFileTypeIdsWhereString("file_type_id"));
				int i = 1;
				for (FileType a : FileType.values()) {
					s.setInt(i++, a.getObj().getId());
				}
				s.executeUpdate();
			} catch (SQLException e) {
				logger.error("SQLException when trying to update process_state for file files that have reprocess flag set.");
				e.printStackTrace();
			}
			
			try {
				
				// go through all files with a process_state of 3 an attempt to delete their child files. if this is successful then set the process_state back to 0 so it can be processed again
				PreparedStatement s = dbConnection.prepareStatement("SELECT * FROM files WHERE ((heartbeat IS NULL OR heartbeat<?) AND process_state=3)"+getFileTypeIdsWhereString("file_type_id"));
				
				int i = 1;
				s.setTimestamp(i++, heartbeatManager.getProcessingFilesTimestamp());
				for (FileType a : FileType.values()) {
					s.setInt(i++, a.getObj().getId());
				}
				ResultSet r = s.executeQuery();
				
				while(r.next()) {
					File file = DbHelper.buildFileFromResult(r);
					logger.info("Found file with id "+file.getId()+" that wants reprocessing.");
					if (!HeartbeatManager.getInstance().registerFile(file)) {
						logger.info("File with id "+file.getId()+" cannot be reprocessed now as it is being used somewhere else.");
						continue;
					}
					try {
						logger.info("Attempting to remove any child files it has.");
						if (!removeChildFilesAndRecords(dbConnection, file, false)) {
							logger.warn("Some child files could not be removed for some reason. Not resetting process_state to 0.");
						}
						else {
							// set process_state to 0 so that it will be picked up for processing again
							s = dbConnection.prepareStatement("UPDATE files SET process_state=0 WHERE id=?");
							s.setInt(1, file.getId());
							if (s.executeUpdate() != 1) {
								logger.error("There was an error setting the process_state for file with id "+file.getId()+".");
							}
							
							DbHelper.updateStatus(dbConnection, file.getId(), "Waiting to be reprocessed.", null);
							logger.info("File with id "+file.getId()+" is now ready for reprocessing.");
						}
						HeartbeatManager.getInstance().unRegisterFile(file);
					}
					catch(Exception e) {
						// an exception occurred so unregister the file and then rethrow the exception.
						HeartbeatManager.getInstance().unRegisterFile(file);
						throw(e);
					}
				}
				s.close();
			} catch (SQLException e) {
				logger.error("SQLException when trying setup a file for reprocessing.");
				e.printStackTrace();
			}
			
			logger.info("Finished looking for files that are set to be reprocessed.");
		}