-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProcessorSettings.go
More file actions
61 lines (49 loc) · 2.08 KB
/
ProcessorSettings.go
File metadata and controls
61 lines (49 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package jrm1
import "errors"
const (
ErrEnableExceptionCaptureToLogThem = "enable exception capture to log them"
ErrMetaDataFieldNameConflict = "meta data field name conflict"
)
// ProcessorSettings are settings of the RPC processor (server).
type ProcessorSettings struct {
// When enabled, RPC processor (server) will catch exceptions.
CatchExceptions bool
// When enabled, RPC processor (server) will journal exceptions.
LogExceptions bool
// When enabled, RPC processor (server) will count requests.
CountRequests bool
// Name of a meta-data field where to store request duration.
// When enabled, RPC processor (server) will measure time taken to run
// functions. Duration is shown only for successful function calls.
// To enable this feature, set the field name as non-null value.
DurationFieldName *string
// Name of a meta-data field where to store ID of the current request.
// When enabled, RPC processor (server) will add ID of the current request
// as a meta-data field, so that user function will be able to read it.
// This field is automatically removed when function call finishes.
// To enable this feature, set the field name as non-null value.
RequestIdFieldName *string
}
// Check verifies processor's settings.
func (ps *ProcessorSettings) Check() (err error) {
if ps.LogExceptions && (!ps.CatchExceptions) {
return errors.New(ErrEnableExceptionCaptureToLogThem)
}
if ps.DurationFieldName != nil && ps.RequestIdFieldName != nil {
if *ps.DurationFieldName == *ps.RequestIdFieldName {
return errors.New(ErrMetaDataFieldNameConflict)
}
}
return nil
}
// isDurationEnabled tells whether time measurement is enabled.
func (ps *ProcessorSettings) isDurationEnabled() bool {
return ps.DurationFieldName != nil
}
// isRequestIdShown tells whether request ID is added to the meta-data set.
// Note that request ID is added to the meta-data set only for the duration of
// the function call. When the requested function returns, the ID is removed
// from the meta-data set.
func (ps *ProcessorSettings) isRequestIdShown() bool {
return ps.RequestIdFieldName != nil
}