(requestID string)
| 84 | } |
| 85 | |
| 86 | func (h *AsyncMessageHandler) handleMessage(requestID string) error { |
| 87 | h.log.Infow("processing workload", "id", requestID) |
| 88 | |
| 89 | err := h.updateStatus(requestID, async.StatusInProgress) |
| 90 | if err != nil { |
| 91 | return errors.Wrap(err, fmt.Sprintf("failed to update status to %s", async.StatusInProgress)) |
| 92 | } |
| 93 | |
| 94 | payload, err := h.getPayload(requestID) |
| 95 | if err != nil { |
| 96 | updateStatusErr := h.updateStatus(requestID, async.StatusFailed) |
| 97 | if updateStatusErr != nil { |
| 98 | h.log.Errorw("failed to update status after failure to get payload", "id", requestID, "error", updateStatusErr) |
| 99 | } |
| 100 | return errors.Wrap(err, "failed to get payload") |
| 101 | } |
| 102 | defer func() { |
| 103 | h.deletePayload(requestID) |
| 104 | _ = payload.Close() |
| 105 | }() |
| 106 | |
| 107 | headers, err := h.getHeaders(requestID) |
| 108 | if err != nil { |
| 109 | updateStatusErr := h.updateStatus(requestID, async.StatusFailed) |
| 110 | if updateStatusErr != nil { |
| 111 | h.log.Errorw("failed to update status after failure to get headers", "id", requestID, "error", updateStatusErr) |
| 112 | } |
| 113 | return errors.Wrap(err, "failed to get payload") |
| 114 | } |
| 115 | |
| 116 | result, err := h.submitRequest(payload, headers, requestID) |
| 117 | if err != nil { |
| 118 | h.log.Errorw("failed to submit request to user container", "id", requestID, "error", err) |
| 119 | updateStatusErr := h.updateStatus(requestID, async.StatusFailed) |
| 120 | if updateStatusErr != nil { |
| 121 | return errors.Wrap(updateStatusErr, fmt.Sprintf("failed to update status to %s", async.StatusFailed)) |
| 122 | } |
| 123 | return nil |
| 124 | } |
| 125 | |
| 126 | if err = h.uploadResult(requestID, result); err != nil { |
| 127 | updateStatusErr := h.updateStatus(requestID, async.StatusFailed) |
| 128 | if updateStatusErr != nil { |
| 129 | h.log.Errorw("failed to update status after failure to upload result", "id", requestID, "error", updateStatusErr) |
| 130 | } |
| 131 | return errors.Wrap(err, "failed to upload result to storage") |
| 132 | } |
| 133 | |
| 134 | if err = h.updateStatus(requestID, async.StatusCompleted); err != nil { |
| 135 | return errors.Wrap(err, fmt.Sprintf("failed to update status to %s", async.StatusCompleted)) |
| 136 | } |
| 137 | |
| 138 | h.log.Infow("workload processing complete", "id", requestID) |
| 139 | |
| 140 | return nil |
| 141 | } |
| 142 | |
| 143 | func (h *AsyncMessageHandler) updateStatus(requestID string, status async.Status) error { |
no test coverage detected