|
5 | 5 | "encoding/base64" |
6 | 6 | "errors" |
7 | 7 | "fmt" |
| 8 | + "io" |
8 | 9 | "log" |
9 | 10 | "os" |
10 | 11 | "os/signal" |
@@ -112,27 +113,60 @@ func runPGPush(cfg PGPushConfig) { |
112 | 113 | fmt.Println("Starting PostgreSQL push...") |
113 | 114 | result, err := ps.Push(ctx, forceFull, |
114 | 115 | func(p postgres.PushProgress) { |
115 | | - fmt.Printf( |
116 | | - "\rPushing... %d/%d sessions, %d messages", |
117 | | - p.SessionsDone, p.SessionsTotal, |
118 | | - p.MessagesDone, |
119 | | - ) |
| 116 | + printPGPushProgress(p) |
120 | 117 | }, |
121 | 118 | ) |
122 | 119 | fmt.Print("\r\033[K") // clear progress line |
123 | 120 | if err != nil { |
124 | 121 | fatal("pg push: %v", err) |
125 | 122 | } |
| 123 | + writePGPushSummary(os.Stdout, result) |
| 124 | + if result.Errors > 0 { |
| 125 | + fatal("pg push: %d session(s) failed", |
| 126 | + result.Errors) |
| 127 | + } |
| 128 | +} |
| 129 | + |
| 130 | +func printPGPushProgress(p postgres.PushProgress) { |
| 131 | + if p.SkippedConflicts > 0 { |
| 132 | + fmt.Printf( |
| 133 | + "\rPushing... %d/%d sessions, %d messages, %d ownership conflicts skipped", |
| 134 | + p.SessionsDone, p.SessionsTotal, |
| 135 | + p.MessagesDone, p.SkippedConflicts, |
| 136 | + ) |
| 137 | + return |
| 138 | + } |
126 | 139 | fmt.Printf( |
| 140 | + "\rPushing... %d/%d sessions, %d messages", |
| 141 | + p.SessionsDone, p.SessionsTotal, |
| 142 | + p.MessagesDone, |
| 143 | + ) |
| 144 | +} |
| 145 | + |
| 146 | +func writePGPushSummary(w io.Writer, result postgres.PushResult) { |
| 147 | + if result.SkippedConflicts > 0 { |
| 148 | + fmt.Fprintf( |
| 149 | + w, |
| 150 | + "Pushed %d sessions, %d messages, skipped %d ownership conflict(s) in %s\n", |
| 151 | + result.SessionsPushed, |
| 152 | + result.MessagesPushed, |
| 153 | + result.SkippedConflicts, |
| 154 | + result.Duration.Round(time.Millisecond), |
| 155 | + ) |
| 156 | + fmt.Fprintf( |
| 157 | + w, |
| 158 | + "Warning: skipped %d session(s) owned by another PostgreSQL push marker\n", |
| 159 | + result.SkippedConflicts, |
| 160 | + ) |
| 161 | + return |
| 162 | + } |
| 163 | + fmt.Fprintf( |
| 164 | + w, |
127 | 165 | "Pushed %d sessions, %d messages in %s\n", |
128 | 166 | result.SessionsPushed, |
129 | 167 | result.MessagesPushed, |
130 | 168 | result.Duration.Round(time.Millisecond), |
131 | 169 | ) |
132 | | - if result.Errors > 0 { |
133 | | - fatal("pg push: %d session(s) failed", |
134 | | - result.Errors) |
135 | | - } |
136 | 170 | } |
137 | 171 |
|
138 | 172 | func runPGStatus() { |
|
0 commit comments