func()

in lambda/rapid/handlers.go [221:261]


func (c *rapidContext) watchEvents(events <-chan supvmodel.Event) {
	for event := range events {
		var err error
		log.Debugf("The events handler received the event %+v.", event)
		if loss := event.Event.EventLoss(); loss != nil {
			log.Panicf("Lost %d events from supervisor", *loss)
		}
		termination := event.Event.ProcessTerminated()

		// If we are not shutting down then we care if an unexpected exit happens.
		if !c.shutdownContext.isShuttingDown() {
			runtimeProcessName := fmt.Sprintf("%s-%d", runtimeProcessName, c.runtimeDomainGeneration)

			// If event from the runtime.
			if *termination.Name == runtimeProcessName {
				if termination.Success() {
					err = fmt.Errorf("Runtime exited without providing a reason")
				} else {
					err = fmt.Errorf("Runtime exited with error: %s", termination.String())
				}
				appctx.StoreFirstFatalError(c.appCtx, fatalerror.RuntimeExit)
			} else {
				if termination.Success() {
					err = fmt.Errorf("exit code 0")
				} else {
					err = fmt.Errorf("%s", termination.String())
				}

				appctx.StoreFirstFatalError(c.appCtx, fatalerror.AgentCrash)
			}

			log.Warnf("Process %s exited: %+v", *termination.Name, termination)
		}

		// At the moment we only get termination events.
		// When their are other event types then we would need to be selective,
		// about what we send to handleShutdownEvent().
		c.shutdownContext.handleProcessExit(*termination)
		c.registrationService.CancelFlows(err)
	}
}