Download this file
| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "time" |
| 6 | |
| 7 | "amadan.net/oficina/equipo/internal/hostedctl" |
| 8 | "amadan.net/oficina/equipo/internal/isolatedjob/awsjob" |
| 9 | ) |
| 10 | |
| 11 | // alertTimeout bounds one alert's delivery. hostedctl.New delivers startup |
| 12 | // alerts with a context that never ends, so the alerter sets its own limit. |
| 13 | const alertTimeout = 10 * time.Second |
| 14 | |
| 15 | // snsAlerter delivers the controller's operator alerts to SNS. |
| 16 | type snsAlerter struct { |
| 17 | pub awsjob.SNSPublisher |
| 18 | } |
| 19 | |
| 20 | var _ hostedctl.Alerter = snsAlerter{} |
| 21 | |
| 22 | // Alert publishes a's kind and detail, giving up after alertTimeout. |
| 23 | func (s snsAlerter) Alert(ctx context.Context, a hostedctl.Alert) error { |
| 24 | ctx, cancel := context.WithTimeout(ctx, alertTimeout) |
| 25 | defer cancel() |
| 26 | return s.pub.Publish(ctx, a.Kind, a.Detail) |
| 27 | } |
| 28 | |