@@ -21,6 +21,7 @@ import {
2121 SpaceIdToNamespaceFunction ,
2222 IntervalSchedule ,
2323 Services ,
24+ State ,
2425} from '../types' ;
2526import { promiseResult , map } from './result_type' ;
2627
@@ -149,13 +150,16 @@ export class TaskRunnerFactory {
149150 services : Services ,
150151 { params, throttle, muteAll, mutedInstanceIds } : SavedObject [ 'attributes' ] ,
151152 executionHandler : ReturnType < typeof createExecutionHandler >
152- ) : Promise < Record < string , any > > {
153+ ) : Promise < State > {
153154 const {
154155 params : { alertId } ,
155156 state : { alertInstances : alertRawInstances = { } , alertTypeState = { } } ,
156157 } = taskInstance ;
157158
158- const alertInstances = mapValues ( alertRawInstances , alert => new AlertInstance ( alert ) ) ;
159+ const alertInstances = mapValues < AlertInstances > (
160+ alertRawInstances ,
161+ alert => new AlertInstance ( alert )
162+ ) ;
159163
160164 const updatedAlertTypeState = await alertType . executor ( {
161165 alertId,
@@ -201,6 +205,7 @@ export class TaskRunnerFactory {
201205 async run ( ) {
202206 const {
203207 params : { alertId, spaceId } ,
208+ startedAt : previousStartedAt ,
204209 } = taskInstance ;
205210
206211 const apiKey = await this . getApiKeyForAlertPermissions ( alertId , spaceId ) ;
@@ -223,20 +228,21 @@ export class TaskRunnerFactory {
223228 ) ;
224229
225230 return {
226- state : map < Record < string , any > , Error , Record < string , any > > (
227- await promiseResult < Record < string , any > , Error > (
231+ state : map < State , Error , State > (
232+ await promiseResult < State , Error > (
228233 this . executeAlertInstances ( services , { ...attributes , params } , executionHandler )
229234 ) ,
230- ( stateUpdates : Record < string , any > ) => {
235+ ( stateUpdates : State ) => {
231236 return {
232237 ...stateUpdates ,
233- previousStartedAt : taskInstance . startedAt ! ,
238+ previousStartedAt,
234239 } ;
235240 } ,
236241 ( err : Error ) => {
242+ logger . error ( `Executing Alert "${ alertId } " has resulted in Error: ${ err . message } .` ) ;
237243 return {
238244 ...taskInstance . state ,
239- previousStartedAt : taskInstance . startedAt ! ,
245+ previousStartedAt,
240246 } ;
241247 }
242248 ) ,
0 commit comments