HandleWorkspaceBuildUpdate wraps a callback to parse WorkspaceBuildUpdate messages from the pubsub.
(cb func(ctx context.Context, payload codersdk.WorkspaceBuildUpdate, err error))
| 20 | // HandleWorkspaceBuildUpdate wraps a callback to parse WorkspaceBuildUpdate |
| 21 | // messages from the pubsub. |
| 22 | func HandleWorkspaceBuildUpdate(cb func(ctx context.Context, payload codersdk.WorkspaceBuildUpdate, err error)) func(ctx context.Context, message []byte, err error) { |
| 23 | return func(ctx context.Context, message []byte, err error) { |
| 24 | if err != nil { |
| 25 | cb(ctx, codersdk.WorkspaceBuildUpdate{}, xerrors.Errorf("workspace build update pubsub: %w", err)) |
| 26 | return |
| 27 | } |
| 28 | var payload codersdk.WorkspaceBuildUpdate |
| 29 | if err := json.Unmarshal(message, &payload); err != nil { |
| 30 | cb(ctx, codersdk.WorkspaceBuildUpdate{}, xerrors.Errorf("unmarshal workspace build update: %w", err)) |
| 31 | return |
| 32 | } |
| 33 | cb(ctx, payload, nil) |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | // PublishWorkspaceBuildUpdate is a helper to publish a workspace build update |
| 38 | // to the AllWorkspaceEventChannel. This should be called when a build |
no test coverage detected