CE-936 - Update start method to actually start schedulers; add stop & stopAsync

This commit is contained in:
2024-03-12 13:49:10 -05:00
parent 11d33c6d06
commit 2c4fc6a0d4
2 changed files with 32 additions and 8 deletions

View File

@ -127,6 +127,31 @@ public class QScheduleManager
// ensure that everything which should be scheduled is scheduled, in the appropriate scheduler // // ensure that everything which should be scheduled is scheduled, in the appropriate scheduler //
///////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////
QContext.withTemporaryContext(new CapturedContext(qInstance, systemUserSessionSupplier.get()), () -> setupSchedules()); QContext.withTemporaryContext(new CapturedContext(qInstance, systemUserSessionSupplier.get()), () -> setupSchedules());
//////////////////////////
// start each scheduler //
//////////////////////////
schedulers.values().forEach(s -> s.start());
}
/*******************************************************************************
**
*******************************************************************************/
public void stop()
{
schedulers.values().forEach(s -> s.stop());
}
/*******************************************************************************
**
*******************************************************************************/
public void stopAsync()
{
schedulers.values().forEach(s -> s.stopAsync());
} }
@ -274,5 +299,4 @@ public class QScheduleManager
return (scheduler); return (scheduler);
} }
} }

View File

@ -110,18 +110,18 @@ class SimpleSchedulerTest extends BaseTest
BasicStep.counter = 0; BasicStep.counter = 0;
QScheduleManager qScheduleManager = QScheduleManager.initInstance(qInstance, () -> QContext.getQSession()); QSession qSession = QContext.getQSession();
QScheduleManager qScheduleManager = QScheduleManager.initInstance(qInstance, () -> qSession);
qScheduleManager.start(); qScheduleManager.start();
SimpleScheduler simpleScheduler = SimpleScheduler.getInstance(qInstance); //////////////////////////////////////////////////
simpleScheduler.setSchedulerName(TestUtils.SIMPLE_SCHEDULER_NAME); // give a moment for the job to run a few times //
simpleScheduler.setSessionSupplier(QSession::new); //////////////////////////////////////////////////
simpleScheduler.start();
SleepUtils.sleep(50, TimeUnit.MILLISECONDS); SleepUtils.sleep(50, TimeUnit.MILLISECONDS);
simpleScheduler.stopAsync(); qScheduleManager.stopAsync();
System.out.println("Ran: " + BasicStep.counter + " times"); System.out.println("Ran: " + BasicStep.counter + " times");
assertTrue(BasicStep.counter > 1, "Scheduled process should have ran at least twice"); assertTrue(BasicStep.counter > 1, "Scheduled process should have ran at least twice (but only ran [" + BasicStep.counter + "] time(s).");
} }