write progress in tmp file for tidb-operator, so tidb-operator can retrieve the progress of ebs backup. and user can get the progress through `kubectl get job` todo: maybe change to http api later
(ctx context.Context, progress glue.Progress, total int64, progressFile string)
| 989 | // progress of ebs backup. and user can get the progress through `kubectl get job` |
| 990 | // todo: maybe change to http api later |
| 991 | func progressFileWriterRoutine(ctx context.Context, progress glue.Progress, total int64, progressFile string) { |
| 992 | // remove tmp file |
| 993 | defer func() { |
| 994 | _ = os.Remove(progressFile) |
| 995 | }() |
| 996 | |
| 997 | for progress.GetCurrent() < total { |
| 998 | select { |
| 999 | case <-ctx.Done(): |
| 1000 | return |
| 1001 | case <-time.After(500 * time.Millisecond): |
| 1002 | break |
| 1003 | } |
| 1004 | cur := progress.GetCurrent() |
| 1005 | p := float64(cur) / float64(total) |
| 1006 | p *= 100 |
| 1007 | err := os.WriteFile(progressFile, []byte(fmt.Sprintf("%.2f", p)), 0600) |
| 1008 | if err != nil { |
| 1009 | log.Warn("failed to update tmp progress file", zap.Error(err)) |
| 1010 | } |
| 1011 | } |
| 1012 | } |
| 1013 | |
| 1014 | func WriteStringToConsole(g glue.Glue, msg string) error { |
| 1015 | b := []byte(msg) |