// streamResourceEvents sends a list of ResourceEvent every 3 seconds to the events channel.
// The events channel is closed only when the done channel receives a message.
// If an error occurs while describing stack events, it is ignored so that the stream is not interrupted.
streamResourceEvents sends a list of ResourceEvent every 3 seconds to the events channel.
The events channel is closed only when the done channel receives a message.
If an error occurs while describing stack events, it is ignored so that the stream is not interrupted.
// streamResourceEvents sends a list of ResourceEvent every 3 seconds to the events channel . // The events channel is closed only when the done channel receives a message . // If an error occurs while describing stack events it is ignored so that the stream is not interrupted .
func (cf CloudFormation) streamResourceEvents(done <-chan struct{}, events chan []deploy.ResourceEvent, stackName string) {
	sendStatusUpdates := func() {
		cfEvents, err := cf.cfnClient.Events(stackName)
		if err != nil {
			return
		}
		var transformedEvents []deploy.ResourceEvent
		for _, cfEvent := range cfEvents {
			transformedEvents = append(transformedEvents, deploy.ResourceEvent{
				Resource: deploy.Resource{
					LogicalName: aws.StringValue(cfEvent.LogicalResourceId),
					Type:        aws.StringValue(cfEvent.ResourceType),
				},
				Status: aws.StringValue(cfEvent.ResourceStatus),
				StatusReason: strings.Split(aws.StringValue(cfEvent.ResourceStatusReason), ".")[0],
			})
		}
		events <- transformedEvents
	}
	for {
		timeout := time.After(3 * time.Second)
		select {
		case <-timeout:
			sendStatusUpdates()
		case <-done:
			sendStatusUpdates() 
			close(events)       
			return              
		}
	}
}
func ( cf CloudFormation ) streamResourceEvents ( done <- chan struct { } , events chan [ ] deploy . ResourceEvent , stackName string ) { sendStatusUpdates := func ( ) { cfEvents , err := cf . cfnClient . Events ( stackName ) if err != nil { return } var transformedEvents [ ] deploy . ResourceEvent for _ , cfEvent := range cfEvents { transformedEvents = append ( transformedEvents , deploy . ResourceEvent { Resource : deploy . Resource { LogicalName : aws . StringValue ( cfEvent . LogicalResourceId ) , Type : aws . StringValue ( cfEvent . ResourceType ) , } , Status : aws . StringValue ( cfEvent . ResourceStatus ) , StatusReason : strings . Split ( aws . StringValue ( cfEvent . ResourceStatusReason ) , " " ) [ 0 ] , } ) } events <- transformedEvents } for { timeout := time . After ( 3 * time . Second ) select { case <- timeout : sendStatusUpdates ( ) case <- done : sendStatusUpdates ( ) close ( events ) return } } }
streamResourceEvents sends a list of ResourceEvent every 3 seconds to the events channel.
streamResourceEvents sends a list of ResourceEvent every 3 seconds to the events channel .
// Send a list of ResourceEvent to events if there was no error. // CFN error messages end with a '.' and only the first sentence is useful, the rest is error codes. // Send last batch of updates. // Close the channel to let receivers know that there won't be any more events. // Exit for-loop.