Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Task Manager] Adds a reschedule api to Task Manager #50718

Closed
Closed
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
1082f23
feat(update-scheduled-task): Adds getTask api to Task Store
gmmorris Nov 14, 2019
201748f
feat(update-scheduled-task): Adds reschedule api to Task Manager
gmmorris Nov 18, 2019
1d78a86
Merge branch 'master' into task-manager/update-scheduled-task
gmmorris Nov 18, 2019
ea0b47a
refactor(update-scheduled-task): clean up reschedule code
gmmorris Nov 18, 2019
be1d700
refactor(update-scheduled-task): separate default value from serialis…
gmmorris Nov 18, 2019
2a289cd
Merge remote-tracking branch 'upstream/master' into task-manager/upda…
gmmorris Nov 19, 2019
9220454
feat(update-scheduled-task): simplified reschedule api to reuse exist…
gmmorris Nov 19, 2019
dbdc3f8
Merge branch 'master' into task-manager/update-scheduled-task
gmmorris Nov 19, 2019
fce851d
refactor(update-scheduled-task): removed unneeded interval func
gmmorris Nov 19, 2019
baec6e7
refactor(update-scheduled-task): reuse type
gmmorris Nov 20, 2019
e04cc60
refactor(update-scheduled-task): clean up task serialisation
gmmorris Nov 20, 2019
6fe4f78
doc(update-scheduled-task): documented `reschedule` api in README
gmmorris Nov 20, 2019
9e4cc56
Merge branch 'master' into task-manager/update-scheduled-task
gmmorris Nov 20, 2019
bf24701
doc(update-scheduled-task): corrected description of type
gmmorris Nov 20, 2019
cd64151
renamed rescheduling type
gmmorris Nov 20, 2019
67c651c
renamed methjods in store to reflect subject
gmmorris Nov 20, 2019
cbfc42c
explicitly pick out properties in serialisation
gmmorris Nov 20, 2019
b691b1e
introduce retry into Task rescheduling
gmmorris Nov 21, 2019
ed78933
Merge branch 'master' into task-manager/update-scheduled-task
gmmorris Nov 21, 2019
0abcf92
Merge branch 'master' into task-manager/update-scheduled-task
gmmorris Nov 21, 2019
fcbedee
Merge branch 'master' into task-manager/update-scheduled-task
gmmorris Nov 21, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor(update-scheduled-task): removed unneeded interval func
gmmorris committed Nov 19, 2019
commit fce851da7829636d6604a2fa7b2814f1fb3fca89
29 changes: 0 additions & 29 deletions x-pack/legacy/plugins/task_manager/lib/intervals.test.ts
Original file line number Diff line number Diff line change
@@ -10,7 +10,6 @@ import {
assertValidInterval,
intervalFromNow,
intervalFromDate,
precedingDateByInterval,
minutesFromNow,
minutesFromDate,
secondsFromNow,
@@ -163,32 +162,4 @@ describe('taskIntervals', () => {
expect(expected).toEqual(nextRun);
});
});

describe('precedingDateByInterval', () => {
test('it rejects intervals are not of the form `Nm` or `Ns`', () => {
const date = new Date();
expect(() => precedingDateByInterval(date, `5m 2s`)).toThrow(
/Invalid interval "5m 2s"\. Intervals must be of the form {number}m. Example: 5m/
);
expect(() => precedingDateByInterval(date, `hello`)).toThrow(
/Invalid interval "hello"\. Intervals must be of the form {number}m. Example: 5m/
);
});

test('it returns the date preceding a given date by subtracting a minute interval from it', () => {
const succeedingDate = new Date(2019, 1, 1);
const mins = _.random(1, 100);
const expected = succeedingDate.valueOf() - mins * 60 * 1000;
const precedingTime = precedingDateByInterval(succeedingDate, `${mins}m`)!.getTime();
expect(expected).toEqual(precedingTime);
});

test('it returns the date preceding a given date by subtracting a seconds interval from it', () => {
const succeedingDate = new Date(2019, 1, 1);
const seconds = _.random(1, 1000);
const expected = succeedingDate.valueOf() - seconds * 1000;
const precedingTime = precedingDateByInterval(succeedingDate, `${seconds}s`)!.getTime();
expect(expected).toEqual(precedingTime);
});
});
});
16 changes: 0 additions & 16 deletions x-pack/legacy/plugins/task_manager/lib/intervals.ts
Original file line number Diff line number Diff line change
@@ -45,18 +45,6 @@ export function intervalFromDate(date: Date, interval?: string): Date | undefine
return minutesFromDate(date, parseInterval(interval));
}

export function precedingDateByInterval(date: Date, interval?: string): Date | undefined {
if (interval === undefined) {
return;
}

assertValidInterval(interval);

return isSeconds(interval)
? secondsFromDate(date, negative(parseInterval(interval)))
: minutesFromDate(date, negative(parseInterval(interval)));
}

/**
* Returns a date that is mins minutes from now.
*
@@ -133,7 +121,3 @@ function isMinutes(interval: string) {
function isSeconds(interval: string) {
return /^[1-9][0-9]*s$/.test(interval);
}

function negative(n: number): number {
return -n;
}