pass previousStartedAt as Date into Alert executor (#54576)

Corrects how we pass previousStartedAt into Alert executor
This commit is contained in:
Gidi Meir Morris 2020-01-13 17:15:08 +00:00 committed by GitHub
parent 6826ece3b0
commit e54a7175da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 8 deletions

View file

@ -38,9 +38,7 @@ describe('Task Runner', () => {
scheduledAt: new Date(),
startedAt: new Date(),
retryAt: new Date(Date.now() + 5 * 60 * 1000),
state: {
startedAt: new Date(Date.now() - 5 * 60 * 1000),
},
state: {},
taskType: 'alerting:test',
params: {
alertId: '1',
@ -110,7 +108,13 @@ describe('Task Runner', () => {
test('successfully executes the task', async () => {
const taskRunner = new TaskRunner(
alertType,
mockedTaskInstance,
{
...mockedTaskInstance,
state: {
...mockedTaskInstance.state,
previousStartedAt: new Date(Date.now() - 5 * 60 * 1000).toISOString(),
},
},
taskRunnerFactoryInitializerParams
);
savedObjectsClient.get.mockResolvedValueOnce(mockedAlertTypeSavedObject);
@ -141,6 +145,7 @@ describe('Task Runner', () => {
}
`);
expect(call.startedAt).toMatchInlineSnapshot(`1970-01-01T00:00:00.000Z`);
expect(call.previousStartedAt).toMatchInlineSnapshot(`1969-12-31T23:55:00.000Z`);
expect(call.state).toMatchInlineSnapshot(`Object {}`);
expect(call.name).toBe('alert-name');
expect(call.tags).toEqual(['alert-', '-tags']);
@ -261,7 +266,6 @@ describe('Task Runner', () => {
"runAt": 1970-01-01T00:00:10.000Z,
"state": Object {
"previousStartedAt": 1970-01-01T00:00:00.000Z,
"startedAt": 1969-12-31T23:55:00.000Z,
},
}
`);
@ -293,7 +297,6 @@ describe('Task Runner', () => {
"runAt": 1970-01-01T00:00:10.000Z,
"state": Object {
"previousStartedAt": 1970-01-01T00:00:00.000Z,
"startedAt": 1969-12-31T23:55:00.000Z,
},
}
`);
@ -400,7 +403,6 @@ describe('Task Runner', () => {
"runAt": 1970-01-01T00:00:10.000Z,
"state": Object {
"previousStartedAt": 1970-01-01T00:00:00.000Z,
"startedAt": 1969-12-31T23:55:00.000Z,
},
}
`);

View file

@ -152,7 +152,7 @@ export class TaskRunner {
params,
state: alertTypeState,
startedAt: this.taskInstance.startedAt!,
previousStartedAt,
previousStartedAt: previousStartedAt && new Date(previousStartedAt),
spaceId,
namespace,
name,