MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / NewSyncRunnerWithLogging

Function NewSyncRunnerWithLogging

channels/sync_runner.go:119–211  ·  view source on GitHub ↗
(ctx context.Context, funcSource string, timeout time.Duration, errorLogFunc, infoLogFunc func(string))

Source from the content-addressed store, hash-verified

117}
118
119func NewSyncRunnerWithLogging(ctx context.Context, funcSource string, timeout time.Duration, errorLogFunc, infoLogFunc func(string)) (*SyncRunner, error) {
120 funcSource = wrappedFuncSource(funcSource)
121 runner := &SyncRunner{}
122 err := runner.InitWithLogging(funcSource, timeout, errorLogFunc, infoLogFunc)
123 if err != nil {
124 return nil, err
125 }
126
127 // Implementation of the 'channel()' callback:
128 runner.DefineNativeFunction("channel", func(call otto.FunctionCall) otto.Value {
129 for _, arg := range call.ArgumentList {
130 if strings := ottoValueToStringArray(ctx, arg); strings != nil {
131 runner.channels = append(runner.channels, strings...)
132 }
133 }
134 return otto.UndefinedValue()
135 })
136
137 // Implementation of the 'access()' callback:
138 runner.DefineNativeFunction("access", func(call otto.FunctionCall) otto.Value {
139 return runner.addValueForUser(ctx, call.Argument(0), call.Argument(1), runner.access)
140 })
141
142 // Implementation of the 'role()' callback:
143 runner.DefineNativeFunction("role", func(call otto.FunctionCall) otto.Value {
144 return runner.addValueForUser(ctx, call.Argument(0), call.Argument(1), runner.roles)
145 })
146
147 // Implementation of the 'reject()' callback:
148 runner.DefineNativeFunction("reject", func(call otto.FunctionCall) otto.Value {
149 if runner.output.Rejection == nil {
150 if status, err := call.Argument(0).ToInteger(); err == nil && status >= 400 {
151 var message string
152 if len(call.ArgumentList) > 1 {
153 message = call.Argument(1).String()
154 }
155 runner.output.Rejection = base.NewHTTPError(int(status), message)
156 }
157 }
158 return otto.UndefinedValue()
159 })
160
161 // Implementation of the 'expiry()' callback:
162 runner.DefineNativeFunction("expiry", func(call otto.FunctionCall) otto.Value {
163 if len(call.ArgumentList) > 0 {
164 rawExpiry, exportErr := call.Argument(0).Export()
165 if exportErr != nil {
166 base.WarnfCtx(ctx, "SyncRunner: Unable to export expiry parameter: %v Error: %s", call.Argument(0), exportErr)
167 return otto.UndefinedValue()
168 }
169
170 // Called expiry with null/undefined value - ignore
171 if rawExpiry == nil || call.Argument(0).IsUndefined() {
172 return otto.UndefinedValue()
173 }
174
175 expiry, reflectErr := base.ReflectExpiry(rawExpiry)
176 if reflectErr != nil {

Callers 2

SyncFnDryRunMethod · 0.92
NewSyncRunnerFunction · 0.85

Calls 9

addValueForUserMethod · 0.95
NewHTTPErrorFunction · 0.92
WarnfCtxFunction · 0.92
ReflectExpiryFunction · 0.92
wrappedFuncSourceFunction · 0.85
ottoValueToStringArrayFunction · 0.85
compileAccessMapFunction · 0.85
SetFromArrayFunction · 0.70
StringMethod · 0.65

Tested by

no test coverage detected