MCPcopy Create free account
hub / github.com/krau/SaveAny-Bot / Emit

Method Emit

api/progress.go:158–200  ·  view source on GitHub ↗

Emit implements taskevent.Sink. It translates task lifecycle events into status/progress updates and fires the webhook on terminal transitions.

(e taskevent.Event)

Source from the content-addressed store, hash-verified

156// Emit implements taskevent.Sink. It translates task lifecycle events into
157// status/progress updates and fires the webhook on terminal transitions.
158func (t *TaskProgressInfo) Emit(e taskevent.Event) {
159 t.mu.Lock()
160 switch e.Phase {
161 case taskevent.PhaseStart:
162 t.Status = TaskStatusRunning
163 if t.StartedAt.IsZero() {
164 t.StartedAt = time.Now()
165 }
166 if e.TotalBytes > 0 {
167 t.TotalBytes = e.TotalBytes
168 }
169 case taskevent.PhaseProgress:
170 t.Status = TaskStatusRunning
171 if e.TotalBytes > 0 {
172 t.TotalBytes = e.TotalBytes
173 }
174 t.DownloadedBytes = e.DownloadedBytes
175 if e.TotalFiles > 0 {
176 t.TotalFiles = e.TotalFiles
177 }
178 if e.DownloadedFiles > 0 {
179 t.DownloadedFiles = e.DownloadedFiles
180 }
181 case taskevent.PhaseDone:
182 if e.Err != nil {
183 t.Status = TaskStatusFailed
184 t.Error = e.Err.Error()
185 } else {
186 t.Status = TaskStatusCompleted
187 }
188 }
189 t.UpdatedAt = time.Now()
190 notify := t.Webhook != "" && !t.webhookNotified && (t.Status == TaskStatusCompleted || t.Status == TaskStatusFailed)
191 if notify {
192 t.webhookNotified = true
193 }
194 t.mu.Unlock()
195
196 if notify {
197 payload := CreateWebhookPayload(t.TaskID, t.Type, t.Status, t.Storage, t.Path, e.Err)
198 SendWebhook(nil, payload)
199 }
200}
201
202// ProgressTracker is retained for compatibility but is no longer the primary
203// progress path; taskevent drives updates now. These methods are safe no-ops

Callers

nothing calls this directly

Calls 3

CreateWebhookPayloadFunction · 0.85
SendWebhookFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected