(ctx context.Context, eventType string, resource *schema.Resource, version int64)
| 71 | } |
| 72 | |
| 73 | func (tl *transactionEventLogger) logEvent(ctx context.Context, eventType string, resource *schema.Resource, version int64) error { |
| 74 | schemaManager := schema.GetManager() |
| 75 | eventSchema, ok := schemaManager.Schema("event") |
| 76 | if !ok { |
| 77 | return fmt.Errorf("event schema not found") |
| 78 | } |
| 79 | |
| 80 | if resource.Schema().Metadata["nosync"] == true { |
| 81 | log.Debug("skipping event logging for schema: %s", resource.Schema().ID) |
| 82 | return nil |
| 83 | } |
| 84 | |
| 85 | body, err := resource.JSONString() |
| 86 | |
| 87 | syncPlain := false |
| 88 | syncPlainRaw, ok := resource.Schema().Metadata["sync_plain"] |
| 89 | if ok { |
| 90 | syncPlainBool, ok := syncPlainRaw.(bool) |
| 91 | if ok { |
| 92 | syncPlain = syncPlainBool |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | syncProperty := "" |
| 97 | syncPropertyRaw, ok := resource.Schema().Metadata["sync_property"] |
| 98 | if ok { |
| 99 | syncPropertyStr, ok := syncPropertyRaw.(string) |
| 100 | if ok { |
| 101 | syncProperty = syncPropertyStr |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | if err != nil { |
| 106 | return fmt.Errorf("Error during event resource deserialisation: %s", err.Error()) |
| 107 | } |
| 108 | eventResource, err := schema.NewResource(eventSchema, map[string]interface{}{ |
| 109 | "type": eventType, |
| 110 | "path": resource.Path(), |
| 111 | "version": version, |
| 112 | "body": body, |
| 113 | "sync_plain": syncPlain, |
| 114 | "sync_property": syncProperty, |
| 115 | "timestamp": int64(time.Now().Unix()), |
| 116 | }) |
| 117 | tl.eventLogged = true |
| 118 | return tl.Transaction.CreateContext(ctx, eventResource) |
| 119 | } |
| 120 | |
| 121 | func (tl *transactionEventLogger) Create(resource *schema.Resource) error { |
| 122 | return tl.CreateContext(context.Background(), resource) |
no test coverage detected