@Test public void testClearQueue() throws JobHandlerException, InterruptedException { String jobId1 = "abc"; String jobId2 = "def"; File dir1 = new File (jobDir, jobId1); File dir2 = new File (jobDir, jobId2); List<String> cmd = new ArrayList<>(); cmd.add(script.toString()); ((NativeJobManager)jobManager).clearQueue(1000); assertEquals(0, ((NativeJobManager)jobManager).getSize()); String submissionId1 = jobManager.startJob(jobId1, cmd , dir1.toString(),1); String submissionId2 = jobManager.startJob(jobId2, cmd , dir2.toString(),1); assertEquals(2, ((NativeJobManager)jobManager).getSize()); Thread.sleep(SLEEP_TIME*1000+1000); assertEquals(2, ((NativeJobManager)jobManager).getSize()); ((NativeJobManager)jobManager).clearQueue(1000); assertEquals(0, ((NativeJobManager)jobManager).getSize()); }
public void clearQueue(long millisecondsAgo) { Iterator<String> it = tasks.keySet().iterator(); long maxTime = System.currentTimeMillis() - millisecondsAgo; while (it.hasNext()) { String submissionId = it.next(); ShellTask task = tasks.get(submissionId); try { StatusOfJob statusOfJob = getStatusOfJob(task.getJobId(), submissionId); if (task.getSubmissionTime() < maxTime && statusOfJob != StatusOfJob.RUNNING && statusOfJob != StatusOfJob.QUEUING) { it.remove(); } } catch (JobHandlerException e) { logger.warn("Could not get job status for jobId '{}', submissionId '{}'. Will not remove it.", task.getJobId(), submissionId); } } }
NativeJobManager implements JobManager { public void clearQueue(long millisecondsAgo) { Iterator<String> it = tasks.keySet().iterator(); long maxTime = System.currentTimeMillis() - millisecondsAgo; while (it.hasNext()) { String submissionId = it.next(); ShellTask task = tasks.get(submissionId); try { StatusOfJob statusOfJob = getStatusOfJob(task.getJobId(), submissionId); if (task.getSubmissionTime() < maxTime && statusOfJob != StatusOfJob.RUNNING && statusOfJob != StatusOfJob.QUEUING) { it.remove(); } } catch (JobHandlerException e) { logger.warn("Could not get job status for jobId '{}', submissionId '{}'. Will not remove it.", task.getJobId(), submissionId); } } } }
NativeJobManager implements JobManager { public void clearQueue(long millisecondsAgo) { Iterator<String> it = tasks.keySet().iterator(); long maxTime = System.currentTimeMillis() - millisecondsAgo; while (it.hasNext()) { String submissionId = it.next(); ShellTask task = tasks.get(submissionId); try { StatusOfJob statusOfJob = getStatusOfJob(task.getJobId(), submissionId); if (task.getSubmissionTime() < maxTime && statusOfJob != StatusOfJob.RUNNING && statusOfJob != StatusOfJob.QUEUING) { it.remove(); } } catch (JobHandlerException e) { logger.warn("Could not get job status for jobId '{}', submissionId '{}'. Will not remove it.", task.getJobId(), submissionId); } } } NativeJobManager(String jobsDirectory, int numWorkers); }
NativeJobManager implements JobManager { public void clearQueue(long millisecondsAgo) { Iterator<String> it = tasks.keySet().iterator(); long maxTime = System.currentTimeMillis() - millisecondsAgo; while (it.hasNext()) { String submissionId = it.next(); ShellTask task = tasks.get(submissionId); try { StatusOfJob statusOfJob = getStatusOfJob(task.getJobId(), submissionId); if (task.getSubmissionTime() < maxTime && statusOfJob != StatusOfJob.RUNNING && statusOfJob != StatusOfJob.QUEUING) { it.remove(); } } catch (JobHandlerException e) { logger.warn("Could not get job status for jobId '{}', submissionId '{}'. Will not remove it.", task.getJobId(), submissionId); } } } NativeJobManager(String jobsDirectory, int numWorkers); @Override String startJob(String jobId,
						   List<String> command,
						   String jobDirectory,
						   int nrOfThreadsForSubmission); @Override StatusOfJob getStatusOfJob(String jobId, String submissionId); @Override void stopJob(String submissionId); @Override void close(); void clearQueue(long millisecondsAgo); int getSize(); void logJobHistory(); }
NativeJobManager implements JobManager { public void clearQueue(long millisecondsAgo) { Iterator<String> it = tasks.keySet().iterator(); long maxTime = System.currentTimeMillis() - millisecondsAgo; while (it.hasNext()) { String submissionId = it.next(); ShellTask task = tasks.get(submissionId); try { StatusOfJob statusOfJob = getStatusOfJob(task.getJobId(), submissionId); if (task.getSubmissionTime() < maxTime && statusOfJob != StatusOfJob.RUNNING && statusOfJob != StatusOfJob.QUEUING) { it.remove(); } } catch (JobHandlerException e) { logger.warn("Could not get job status for jobId '{}', submissionId '{}'. Will not remove it.", task.getJobId(), submissionId); } } } NativeJobManager(String jobsDirectory, int numWorkers); @Override String startJob(String jobId,
						   List<String> command,
						   String jobDirectory,
						   int nrOfThreadsForSubmission); @Override StatusOfJob getStatusOfJob(String jobId, String submissionId); @Override void stopJob(String submissionId); @Override void close(); void clearQueue(long millisecondsAgo); int getSize(); void logJobHistory();  }