| 55 | } |
| 56 | |
| 57 | func HandleWorkspaceEvent(cb func(ctx context.Context, payload WorkspaceEvent, err error)) func(ctx context.Context, message []byte, err error) { |
| 58 | return func(ctx context.Context, message []byte, err error) { |
| 59 | if err != nil { |
| 60 | cb(ctx, WorkspaceEvent{}, xerrors.Errorf("workspace event pubsub: %w", err)) |
| 61 | return |
| 62 | } |
| 63 | var payload WorkspaceEvent |
| 64 | if err := json.Unmarshal(message, &payload); err != nil { |
| 65 | cb(ctx, WorkspaceEvent{}, xerrors.Errorf("unmarshal workspace event")) |
| 66 | return |
| 67 | } |
| 68 | if err := payload.Validate(); err != nil { |
| 69 | cb(ctx, payload, xerrors.Errorf("validate workspace event")) |
| 70 | return |
| 71 | } |
| 72 | cb(ctx, payload, err) |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | type WorkspaceEvent struct { |
| 77 | Kind WorkspaceEventKind `json:"kind"` |