forked from Silverfish/proton-bridge
fix(GODT-2774): Add external context to telemetry tasks
This ensures they get cancelled if the parent context becomes invalid
This commit is contained in:
committed by
Romain LE JEUNE
parent
6579cdfc7f
commit
c4f80103b6
@ -18,6 +18,7 @@
|
||||
package telemetry
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
@ -149,12 +150,12 @@ func (heartbeat *Heartbeat) SetPrevVersion(val string) {
|
||||
heartbeat.metrics.Dimensions.PrevVersion = val
|
||||
}
|
||||
|
||||
func (heartbeat *Heartbeat) TrySending() {
|
||||
if heartbeat.manager.IsTelemetryAvailable() {
|
||||
func (heartbeat *Heartbeat) TrySending(ctx context.Context) {
|
||||
if heartbeat.manager.IsTelemetryAvailable(ctx) {
|
||||
lastSent := heartbeat.manager.GetLastHeartbeatSent()
|
||||
now := time.Now()
|
||||
if now.Year() > lastSent.Year() || (now.Year() == lastSent.Year() && now.YearDay() > lastSent.YearDay()) {
|
||||
if !heartbeat.manager.SendHeartbeat(&heartbeat.metrics) {
|
||||
if !heartbeat.manager.SendHeartbeat(ctx, &heartbeat.metrics) {
|
||||
heartbeat.log.WithFields(logrus.Fields{
|
||||
"metrics": heartbeat.metrics,
|
||||
}).Error("Failed to send heartbeat")
|
||||
|
||||
Reference in New Issue
Block a user