mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 05:01:07 +00:00
CE-936 - Update start method to actually start schedulers; add stop & stopAsync
This commit is contained in:
@ -127,6 +127,31 @@ public class QScheduleManager
|
||||
// ensure that everything which should be scheduled is scheduled, in the appropriate scheduler //
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -110,18 +110,18 @@ class SimpleSchedulerTest extends BaseTest
|
||||
|
||||
BasicStep.counter = 0;
|
||||
|
||||
QScheduleManager qScheduleManager = QScheduleManager.initInstance(qInstance, () -> QContext.getQSession());
|
||||
QSession qSession = QContext.getQSession();
|
||||
QScheduleManager qScheduleManager = QScheduleManager.initInstance(qInstance, () -> qSession);
|
||||
qScheduleManager.start();
|
||||
|
||||
SimpleScheduler simpleScheduler = SimpleScheduler.getInstance(qInstance);
|
||||
simpleScheduler.setSchedulerName(TestUtils.SIMPLE_SCHEDULER_NAME);
|
||||
simpleScheduler.setSessionSupplier(QSession::new);
|
||||
simpleScheduler.start();
|
||||
//////////////////////////////////////////////////
|
||||
// give a moment for the job to run a few times //
|
||||
//////////////////////////////////////////////////
|
||||
SleepUtils.sleep(50, TimeUnit.MILLISECONDS);
|
||||
simpleScheduler.stopAsync();
|
||||
qScheduleManager.stopAsync();
|
||||
|
||||
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).");
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user