MCPcopy Create free account
hub / github.com/cloudwan/gohan / logEvent

Method logEvent

server/transaction_commit_informer.go:73–119  ·  view source on GitHub ↗
(ctx context.Context, eventType string, resource *schema.Resource, version int64)

Source from the content-addressed store, hash-verified

71}
72
73func (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
121func (tl *transactionEventLogger) Create(resource *schema.Resource) error {
122 return tl.CreateContext(context.Background(), resource)

Callers 4

CreateContextMethod · 0.95
UpdateContextMethod · 0.95
ResyncMethod · 0.95
DeleteContextMethod · 0.95

Calls 7

JSONStringMethod · 0.80
PathMethod · 0.80
SchemaMethod · 0.65
ErrorfMethod · 0.65
DebugMethod · 0.65
ErrorMethod · 0.65
CreateContextMethod · 0.65

Tested by

no test coverage detected