mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-24 19:06:44 +00:00
feat(GODT-2713): Send config_progress event once a day if the configuration is stucked in pending for more than a day.
This commit is contained in:
@ -82,4 +82,33 @@ func (user *User) SendConfigStatusRecovery() {
|
||||
}
|
||||
|
||||
func (user *User) SendConfigStatusProgress() {
|
||||
if !user.telemetryManager.IsTelemetryAvailable() {
|
||||
return
|
||||
}
|
||||
if !user.configStatus.IsPending() {
|
||||
return
|
||||
}
|
||||
|
||||
var builder configstatus.ConfigProgressBuilder
|
||||
progress := builder.New(user.configStatus.Data)
|
||||
if progress.Values.NbDaySinceLast == 0 || progress.Values.NbDay == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
data, err := json.Marshal(progress)
|
||||
if err != nil {
|
||||
if err := user.reporter.ReportMessageWithContext("Cannot parse config_progress data.", reporter.Context{
|
||||
"error": err,
|
||||
}); err != nil {
|
||||
user.log.WithError(err).Error("Failed to report config_progress data parsing error.")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if err := user.SendTelemetry(context.Background(), data); err == nil {
|
||||
user.log.Info("Configuration Status Progress event sent.")
|
||||
if err := user.configStatus.ApplyProgress(); err != nil {
|
||||
user.log.WithError(err).Error("Failed to ApplyProgress on config_status.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -98,6 +98,8 @@ type User struct {
|
||||
|
||||
configStatus *configstatus.ConfigurationStatus
|
||||
telemetryManager telemetry.Availability
|
||||
// goStatusProgress triggers a check/sending if progress is needed.
|
||||
goStatusProgress func()
|
||||
}
|
||||
|
||||
// New returns a new user.
|
||||
@ -176,6 +178,12 @@ func New(
|
||||
telemetryManager: telemetryManager,
|
||||
}
|
||||
|
||||
// Check for status_progress when triggered.
|
||||
user.goStatusProgress = user.tasks.PeriodicOrTrigger(configstatus.ProgressCheckInterval, 0, func(ctx context.Context) {
|
||||
user.SendConfigStatusProgress()
|
||||
})
|
||||
defer user.goStatusProgress()
|
||||
|
||||
// Initialize the user's update channels for its current address mode.
|
||||
user.initUpdateCh(encVault.AddressMode())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user