Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions internal/api/handlers/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,15 @@ func (h *TaskHandler) OnRecordingFinish(c *gin.Context) {

logger.Printf("[RECORDER] Device %s: received finish callback for task=%s", callback.DeviceID, callback.TaskID)

if h.db != nil {
res, err := advanceTaskPendingOrReadyToInProgress(h.db, callback.TaskID)
if err != nil {
logger.Printf("[RECORDER] Device %s: failed to restore task pending/ready->in_progress after finish callback: task=%s err=%v", deviceID, callback.TaskID, err)
} else if n, _ := res.RowsAffected(); n > 0 {
logger.Printf("[RECORDER] Device %s: task status reconciled: task=%s source=finish_callback status=in_progress", deviceID, callback.TaskID)
}
}

dc := h.hub.Get(deviceID)
if dc == nil {
// TODO: add status pending_upload, when device reconnects, check for any pending_upload tasks and trigger upload then
Expand Down
8 changes: 7 additions & 1 deletion internal/api/handlers/task_state_recovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,11 +426,15 @@ func TestTaskHandlerAxonTransferWriteTimeout(t *testing.T) {
}

func TestRecordingFinishAutoUploadUsesConfiguredTransferWriteTimeout(t *testing.T) {
db := newTaskStateRecoveryDB(t)
defer db.Close()
seedTaskStateRecoveryTask(t, db, "task-finish", "pending")

custom := 250 * time.Millisecond
hub := &recordingFinishTransferHub{
conn: &services.TransferConn{DeviceID: "robot-001"},
}
handler := &TaskHandler{hub: hub, transferWriteTimeout: custom}
handler := &TaskHandler{db: db, hub: hub, transferWriteTimeout: custom}

gin.SetMode(gin.TestMode)
router := gin.New()
Expand Down Expand Up @@ -470,6 +474,8 @@ func TestRecordingFinishAutoUploadUsesConfiguredTransferWriteTimeout(t *testing.
if got := fmt.Sprint(hub.msg["task_id"]); got != "task-finish" {
t.Fatalf("message task_id=%q want=%q", got, "task-finish")
}
assertTaskStateRecoveryStatus(t, db, "task-finish", "in_progress")
assertTaskStateRecoveryTimestampSet(t, db, "task-finish", "started_at")
if !strings.Contains(w.Body.String(), custom.String()) {
t.Fatalf("response body %q does not mention custom timeout %s", w.Body.String(), custom)
}
Expand Down
Loading