Fix bug causing search to be empty initially.
Signed-off-by: Eric Peterson <ericpeterson@spotify.com>
This commit is contained in:
@@ -74,4 +74,21 @@ describe('Scheduler', () => {
|
||||
expect(mockTask2).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('start', () => {
|
||||
it('should execute tasks on start', () => {
|
||||
const mockTask1 = jest.fn();
|
||||
const mockTask2 = jest.fn();
|
||||
|
||||
// Add tasks and interval to schedule
|
||||
testScheduler.addToSchedule(mockTask1, 2);
|
||||
testScheduler.addToSchedule(mockTask2, 2);
|
||||
|
||||
// Starts scheduling process
|
||||
testScheduler.start();
|
||||
|
||||
expect(mockTask1).toHaveBeenCalled();
|
||||
expect(mockTask2).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -54,6 +54,8 @@ export class Scheduler {
|
||||
start() {
|
||||
this.logger.info('Starting all scheduled search tasks.');
|
||||
this.schedule.forEach(({ task, interval }) => {
|
||||
// Fire the task immediately, then schedule it.
|
||||
task();
|
||||
this.intervalTimeouts.push(
|
||||
setInterval(() => {
|
||||
task();
|
||||
|
||||
Reference in New Issue
Block a user