diff --git a/app-service-template/go.mod b/app-service-template/go.mod index 532bd3ebc..b7b7c5a3f 100644 --- a/app-service-template/go.mod +++ b/app-service-template/go.mod @@ -20,7 +20,7 @@ require ( github.com/eclipse/paho.mqtt.golang v1.3.5 // indirect github.com/edgexfoundry/go-mod-bootstrap/v2 v2.1.0 // indirect github.com/edgexfoundry/go-mod-configuration/v2 v2.1.0 // indirect - github.com/edgexfoundry/go-mod-messaging/v2 v2.2.0-dev.6 // indirect + github.com/edgexfoundry/go-mod-messaging/v2 v2.2.0-dev.7 // indirect github.com/edgexfoundry/go-mod-registry/v2 v2.1.0 // indirect github.com/edgexfoundry/go-mod-secrets/v2 v2.1.0 // indirect github.com/fatih/color v1.9.0 // indirect diff --git a/app-service-template/go.sum b/app-service-template/go.sum index 40750f85b..61b8b6b86 100644 --- a/app-service-template/go.sum +++ b/app-service-template/go.sum @@ -59,8 +59,8 @@ github.com/edgexfoundry/go-mod-configuration/v2 v2.1.0/go.mod h1:MvHit0MxBXN4bC8 github.com/edgexfoundry/go-mod-core-contracts/v2 v2.1.0/go.mod h1:I6UhBPCREubcU0ouIGBdZlNG5Xx4NijUVN5rvEtD03k= github.com/edgexfoundry/go-mod-core-contracts/v2 v2.2.0-dev.9 h1:EeXfSNWIHpG6sugmW7DjRcA/faeMS8QirRBU01B1smA= github.com/edgexfoundry/go-mod-core-contracts/v2 v2.2.0-dev.9/go.mod h1:FYFqOHl4OxULCnWecVcBatvk9f/BnRPwivLmARi+YCM= -github.com/edgexfoundry/go-mod-messaging/v2 v2.2.0-dev.6 h1:u9u6eTeXT91ZZfQv0g4T1thi3uB46cMGAUpjTKgP1Yk= -github.com/edgexfoundry/go-mod-messaging/v2 v2.2.0-dev.6/go.mod h1:+X6C0h8ZTJe+lLU2AGJfiAzCJK3zL+yM6cej9VC+79E= +github.com/edgexfoundry/go-mod-messaging/v2 v2.2.0-dev.7 h1:O7C5NBlN03NMSPS7a6vG8ZTO1qyoiiN62HRyDw9dUNk= +github.com/edgexfoundry/go-mod-messaging/v2 v2.2.0-dev.7/go.mod h1:+X6C0h8ZTJe+lLU2AGJfiAzCJK3zL+yM6cej9VC+79E= github.com/edgexfoundry/go-mod-registry/v2 v2.1.0 h1:ks0ejtLLUYKuoKrUBbWxygCU7q2mBFJlHE/+dEzV2Gw= github.com/edgexfoundry/go-mod-registry/v2 v2.1.0/go.mod h1:+MNlQm8Ks9ZmxqrMK4O3KdBA6E7nRK9M+qBtv/1lPcA= github.com/edgexfoundry/go-mod-secrets/v2 v2.1.0 h1:ASVZCZUv6cwM2GVoMJNb7rk5R7cw70S1gsut1yX8OXk= diff --git a/internal/app/service.go b/internal/app/service.go index 5ad41cd4d..7da50279b 100644 --- a/internal/app/service.go +++ b/internal/app/service.go @@ -27,6 +27,7 @@ import ( "strings" "sync" "syscall" + "time" "github.com/edgexfoundry/app-functions-sdk-go/v2/internal" "github.com/edgexfoundry/app-functions-sdk-go/v2/internal/appfunction" @@ -88,6 +89,7 @@ type Service struct { commandLine commandLineFlags flags *flags.Default configProcessor *config.Processor + requestTimeout time.Duration } type commandLineFlags struct { @@ -405,6 +407,11 @@ func (svc *Service) AddFunctionsPipelineForTopics(id string, topics []string, tr return nil } +// RequestTimeout returns the Request Timeout duration that was parsed from the Service.RequestTimeout configuration +func (svc *Service) RequestTimeout() time.Duration { + return svc.requestTimeout +} + // ApplicationSettings returns the values specified in the custom configuration section. func (svc *Service) ApplicationSettings() map[string]string { return svc.config.ApplicationSettings @@ -505,6 +512,14 @@ func (svc *Service) Initialize() error { return fmt.Errorf("boostrapping failed") } + configuration := container.ConfigurationFrom(svc.dic.Get) + var err error + + svc.requestTimeout, err = time.ParseDuration(configuration.Service.RequestTimeout) + if err != nil { + return fmt.Errorf("unable to parse Service.RequestTimeout configuration as a time duration: %s", err.Error()) + } + svc.runtime = runtime.NewGolangRuntime(svc.serviceKey, svc.targetType, svc.dic) // Bootstrapping is complete, so now need to retrieve the needed objects from the containers. diff --git a/pkg/interfaces/mocks/ApplicationService.go b/pkg/interfaces/mocks/ApplicationService.go index a7b9c4423..7be5e9c8a 100644 --- a/pkg/interfaces/mocks/ApplicationService.go +++ b/pkg/interfaces/mocks/ApplicationService.go @@ -14,6 +14,8 @@ import ( mock "github.com/stretchr/testify/mock" registry "github.com/edgexfoundry/go-mod-registry/v2/registry" + + time "time" ) // ApplicationService is an autogenerated mock type for the ApplicationService type @@ -68,19 +70,19 @@ func (_m *ApplicationService) AddBackgroundPublisherWithTopic(capacity int, topi } // AddFunctionsPipelineForTopics provides a mock function with given fields: id, topic, transforms -func (_m *ApplicationService) AddFunctionsPipelineForTopics(id string, topics []string, transforms ...func(interfaces.AppFunctionContext, interface{}) (bool, interface{})) error { +func (_m *ApplicationService) AddFunctionsPipelineForTopics(id string, topic []string, transforms ...func(interfaces.AppFunctionContext, interface{}) (bool, interface{})) error { _va := make([]interface{}, len(transforms)) for _i := range transforms { _va[_i] = transforms[_i] } var _ca []interface{} - _ca = append(_ca, id, topics) + _ca = append(_ca, id, topic) _ca = append(_ca, _va...) ret := _m.Called(_ca...) var r0 error if rf, ok := ret.Get(0).(func(string, []string, ...func(interfaces.AppFunctionContext, interface{}) (bool, interface{})) error); ok { - r0 = rf(id, topics, transforms...) + r0 = rf(id, topic, transforms...) } else { r0 = ret.Error(0) } @@ -450,6 +452,20 @@ func (_m *ApplicationService) RegistryClient() registry.Client { return r0 } +// RequestTimeout provides a mock function with given fields: +func (_m *ApplicationService) RequestTimeout() time.Duration { + ret := _m.Called() + + var r0 time.Duration + if rf, ok := ret.Get(0).(func() time.Duration); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(time.Duration) + } + + return r0 +} + // SetDefaultFunctionsPipeline provides a mock function with given fields: transforms func (_m *ApplicationService) SetDefaultFunctionsPipeline(transforms ...func(interfaces.AppFunctionContext, interface{}) (bool, interface{})) error { _va := make([]interface{}, len(transforms)) diff --git a/pkg/interfaces/service.go b/pkg/interfaces/service.go index 9e6f753a8..1dfd05201 100644 --- a/pkg/interfaces/service.go +++ b/pkg/interfaces/service.go @@ -17,6 +17,7 @@ package interfaces import ( "net/http" + "time" bootstrapInterfaces "github.com/edgexfoundry/go-mod-bootstrap/v2/bootstrap/interfaces" "github.com/edgexfoundry/go-mod-core-contracts/v2/clients/interfaces" @@ -71,6 +72,8 @@ type ApplicationService interface { // A reference to this ApplicationService is add the the context that is passed to the handler, which // can be retrieved using the `AppService` key AddRoute(route string, handler func(http.ResponseWriter, *http.Request), methods ...string) error + // RequestTimeout returns the configured request timeout value from [Service] section. + RequestTimeout() time.Duration // ApplicationSettings returns the key/value map of custom settings ApplicationSettings() map[string]string // GetAppSetting is a convenience function return a setting from the ApplicationSetting