RecordOutput records output JSON from a job. The "output" can be any JSON-encodable value and will be stored in the database on the job row after the current execution attempt completes. Output may be useful for debugging, or for storing the result of a job temporarily without needing to create a de
(ctx context.Context, output any)
| 51 | // The output is marshalled to JSON as part of this function and it will return |
| 52 | // an error if the output is not JSON-encodable. |
| 53 | func RecordOutput(ctx context.Context, output any) error { |
| 54 | metadataUpdates, hasMetadataUpdates := jobexecutor.MetadataUpdatesFromWorkContext(ctx) |
| 55 | if !hasMetadataUpdates { |
| 56 | return errors.New("RecordOutput must be called within a Worker") |
| 57 | } |
| 58 | |
| 59 | outputBytes, err := json.Marshal(output) |
| 60 | if err != nil { |
| 61 | return err |
| 62 | } |
| 63 | |
| 64 | if err := checkOutputSize(outputBytes); err != nil { |
| 65 | return err |
| 66 | } |
| 67 | |
| 68 | metadataUpdates[rivertype.MetadataKeyOutput] = json.RawMessage(outputBytes) |
| 69 | return nil |
| 70 | } |
| 71 | |
| 72 | // Postgres JSONB is limited to 255MB, but it would be a bad idea to get |
| 73 | // anywhere close to that limit for output. |
searching dependent graphs…