Skip to content

Commit

Permalink
refactor!: Rename MakeItRun and MakeItStop APIs to Run and Stop
Browse files Browse the repository at this point in the history
BREAKING CHANGE: MakeItRun renamed to Run and MakeItStop renamed to Stop

Signed-off-by: Leonard Goodell <leonard.goodell@intel.com>
  • Loading branch information
Leonard Goodell committed May 8, 2023
1 parent 5c98e1d commit 7915819
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 63 deletions.
12 changes: 6 additions & 6 deletions app-service-template/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ replace github.com/edgexfoundry/app-functions-sdk-go/v3 => ../

require (
github.com/edgexfoundry/app-functions-sdk-go/v3 v3.0.0-dev.9
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.38
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.39
github.com/google/uuid v1.3.0
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475
github.com/stretchr/testify v1.8.2
Expand All @@ -23,9 +23,9 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/diegoholiveira/jsonlogic/v3 v3.2.7 // indirect
github.com/eclipse/paho.mqtt.golang v1.4.2 // indirect
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.0.0-dev.74 // indirect
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.0.0-dev.79 // indirect
github.com/edgexfoundry/go-mod-configuration/v3 v3.0.0-dev.10 // indirect
github.com/edgexfoundry/go-mod-messaging/v3 v3.0.0-dev.25 // indirect
github.com/edgexfoundry/go-mod-messaging/v3 v3.0.0-dev.28 // indirect
github.com/edgexfoundry/go-mod-registry/v3 v3.0.0-dev.7 // indirect
github.com/edgexfoundry/go-mod-secrets/v3 v3.0.0-dev.14 // indirect
github.com/fatih/color v1.9.0 // indirect
Expand All @@ -35,7 +35,7 @@ require (
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.12.0 // indirect
github.com/go-playground/validator/v10 v10.13.0 // indirect
github.com/go-redis/redis/v7 v7.3.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/gomodule/redigo v2.0.0+incompatible // indirect
Expand All @@ -50,15 +50,15 @@ require (
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hashicorp/serf v0.10.1 // indirect
github.com/leodido/go-urn v1.2.2 // indirect
github.com/leodido/go-urn v1.2.3 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mitchellh/consulstructure v0.0.0-20190329231841-56fdc4d2da54 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/nats-io/nats.go v1.24.0 // indirect
github.com/nats-io/nats.go v1.25.0 // indirect
github.com/nats-io/nkeys v0.4.4 // indirect
github.com/nats-io/nuid v1.0.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
Expand Down
25 changes: 12 additions & 13 deletions app-service-template/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ github.com/diegoholiveira/jsonlogic/v3 v3.2.7 h1:awX07pFPnlntZzRNBcO4a2Ivxa77NMt
github.com/diegoholiveira/jsonlogic/v3 v3.2.7/go.mod h1:9oE8z9G+0OMxOoLHF3fhek3KuqD5CBqM0B6XFL08MSg=
github.com/eclipse/paho.mqtt.golang v1.4.2 h1:66wOzfUHSSI1zamx7jR6yMEI5EuHnT1G6rNA5PM12m4=
github.com/eclipse/paho.mqtt.golang v1.4.2/go.mod h1:JGt0RsEwEX+Xa/agj90YJ9d9DH2b7upDZMK9HRbFvCA=
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.0.0-dev.74 h1:0etq8KnS1VA22tWHTt46V9nNbaLsePPgBbFfF5p+4Yg=
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.0.0-dev.74/go.mod h1:YJB7Dl4+waZfXre+2rIYgA48D1koDwnldScjnK4WAW4=
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.0.0-dev.79 h1:KRgTkaR36hfijNXfyPr0r/D0Ysc0GMinpC5CVu51ocs=
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.0.0-dev.79/go.mod h1:oXI84yFlBa+wNwX92tU7hYLaq/XwhUuBgiVGRLzZpMs=
github.com/edgexfoundry/go-mod-configuration/v3 v3.0.0-dev.10 h1:iDuAO3vpBQnlQuFhai/NATbJkiYXxo3bPCtSnFl07Yw=
github.com/edgexfoundry/go-mod-configuration/v3 v3.0.0-dev.10/go.mod h1:8RlYm5CPzZgUsfXDWVP1TIeUMhsDNIdRdj1HXdomtOI=
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.38 h1:FSu4b6DqviexPsS/ECBR9YgkVB76VSgyMCMDUvyGgNM=
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.38/go.mod h1:1YS2J5NfPCd7TYBk0alu+RR5EBzBb+bnG0KF1qNRQYY=
github.com/edgexfoundry/go-mod-messaging/v3 v3.0.0-dev.25 h1:IElkfO4qZt7+VOmQnsLNB3cDsm5Kfe6cYo/S1RU/2HA=
github.com/edgexfoundry/go-mod-messaging/v3 v3.0.0-dev.25/go.mod h1:04phI5qPCFC2bfG1xZ5h6aiGH8Zp8gKDEljHjo/B+Fs=
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.39 h1:tlw1Bd/hq4D6PQFo3BaN0JUkSqDuAPduaGBYCvoEYTg=
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.39/go.mod h1:zzzWGWij6wAqm1go9TLs++TFMIsBqBb1eRnIj4mRxGw=
github.com/edgexfoundry/go-mod-messaging/v3 v3.0.0-dev.28 h1:7i64Llcg8xRS/kuMDRPcBP0NuKS3tbeiGm0Rz1kUrco=
github.com/edgexfoundry/go-mod-messaging/v3 v3.0.0-dev.28/go.mod h1:/hUUM2+h8ajcQlNuyxCM6PeDE1Tz1S/EfvR4TmJAja8=
github.com/edgexfoundry/go-mod-registry/v3 v3.0.0-dev.7 h1:sje0agoLi8ayEFxGO3xtN7P/IXwjZUUxpC8G2fCTu44=
github.com/edgexfoundry/go-mod-registry/v3 v3.0.0-dev.7/go.mod h1:SGyo4fAHzOhDAd2Usa9RaBT/sOzkbceIqLrDG0+iYy8=
github.com/edgexfoundry/go-mod-secrets/v3 v3.0.0-dev.14 h1:2jG1CBKBXPQdkM8AN1PweaTIaCgudZ6tua/BBBHgq+A=
Expand All @@ -60,8 +60,8 @@ github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/o
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.12.0 h1:E4gtWgxWxp8YSxExrQFv5BpCahla0PVF2oTTEYaWQGI=
github.com/go-playground/validator/v10 v10.12.0/go.mod h1:hCAPuzYvKdP33pxWa+2+6AIKXEKqjIUyqsNCtbsSJrA=
github.com/go-playground/validator/v10 v10.13.0 h1:cFRQdfaSMCOSfGCCLB20MHvuoHb/s5G8L5pu2ppK5AQ=
github.com/go-playground/validator/v10 v10.13.0/go.mod h1:dwu7+CG8/CtBiJFZDz4e+5Upb6OLw04gtBYw0mcG/z4=
github.com/go-redis/redis/v7 v7.3.0 h1:3oHqd0W7f/VLKBxeYTEpqdMUsmMectngjM9OtoRoIgg=
github.com/go-redis/redis/v7 v7.3.0/go.mod h1:JDNMw23GTyLNC4GZu9njt15ctBQVn7xjRfnwdHj/Dcg=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
Expand Down Expand Up @@ -139,8 +139,8 @@ github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/leodido/go-urn v1.2.2 h1:7z68G0FCGvDk646jz1AelTYNYWrTNm0bEcFAo147wt4=
github.com/leodido/go-urn v1.2.2/go.mod h1:kUaIbLZWttglzwNuG0pgsh5vuV6u2YcGBYz1hIPjtOQ=
github.com/leodido/go-urn v1.2.3 h1:6BE2vPT0lqoz3fmOesHZiaiFh7889ssCo2GMvLCfiuA=
github.com/leodido/go-urn v1.2.3/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
Expand Down Expand Up @@ -179,8 +179,8 @@ github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3Rllmb
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/nats-io/jwt/v2 v2.4.1 h1:Y35W1dgbbz2SQUYDPCaclXcuqleVmpbRa7646Jf2EX4=
github.com/nats-io/nats-server/v2 v2.9.16 h1:SuNe6AyCcVy0g5326wtyU8TdqYmcPqzTjhkHojAjprc=
github.com/nats-io/nats.go v1.24.0 h1:CRiD8L5GOQu/DcfkmgBcTTIQORMwizF+rPk6T0RaHVQ=
github.com/nats-io/nats.go v1.24.0/go.mod h1:dVQF+BK3SzUZpwyzHedXsvH3EO38aVKuOPkkHlv5hXA=
github.com/nats-io/nats.go v1.25.0 h1:t5/wCPGciR7X3Mu8QOi4jiJaXaWM8qtkLu4lzGZvYHE=
github.com/nats-io/nats.go v1.25.0/go.mod h1:D2WALIhz7V8M0pH8Scx8JZXlg6Oqz5VG+nQkK8nJdvg=
github.com/nats-io/nkeys v0.4.4 h1:xvBJ8d69TznjcQl9t6//Q5xXuVhyYiSos6RPtvQNTwA=
github.com/nats-io/nkeys v0.4.4/go.mod h1:XUkxdLPTufzlihbamfzQ7mw/VGx6ObUs+0bN5sNvt64=
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
Expand Down Expand Up @@ -213,7 +213,6 @@ github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsT
github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A=
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5XpJzTSTfLsJV/mx9Q9g7kxmchpfZyxgzM=
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/rwtodd/Go.Sed v0.0.0-20210816025313-55464686f9ef/go.mod h1:8AEUvGVi2uQ5b24BIhcr0GCcpd/RNAFWaN2CJFrWIIQ=
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 h1:nn5Wsu0esKSJiIVhscUtVbo7ada43DJhG55ua/hjS5I=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
Expand Down
4 changes: 2 additions & 2 deletions app-service-template/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ func (app *myApp) CreateAndRunAppService(serviceKey string, newServiceFactory fu
return -1
}

if err := app.service.MakeItRun(); err != nil {
app.lc.Errorf("MakeItRun returned error: %s", err.Error())
if err := app.service.Run(); err != nil {
app.lc.Errorf("Run returned error: %s", err.Error())
return -1
}

Expand Down
14 changes: 7 additions & 7 deletions app-service-template/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestCreateAndRunService_Success(t *testing.T) {
})
mockAppService.On("ListenForCustomConfigChanges", mock.Anything, mock.Anything, mock.Anything).
Return(nil)
mockAppService.On("MakeItRun").Return(nil)
mockAppService.On("Run").Return(nil)

return mockAppService, true
}
Expand Down Expand Up @@ -129,11 +129,11 @@ func TestCreateAndRunService_SetFunctionsPipeline_Failed(t *testing.T) {
assert.Equal(t, expected, actual)
}

func TestCreateAndRunService_MakeItRun_Failed(t *testing.T) {
func TestCreateAndRunService_Run_Failed(t *testing.T) {
app := myApp{}

// ensure failure is from MakeItRun
makeItRunCalled := false
// ensure failure is from Run
RunCalled := false

mockFactory := func(_ string) (interfaces.ApplicationService, bool) {
mockAppService := &mocks.ApplicationService{}
Expand All @@ -152,15 +152,15 @@ func TestCreateAndRunService_MakeItRun_Failed(t *testing.T) {
Return(nil)
mockAppService.On("AddFunctionsPipelineForTopics", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
Return(nil)
mockAppService.On("MakeItRun").Return(fmt.Errorf("Failed")).Run(func(args mock.Arguments) {
makeItRunCalled = true
mockAppService.On("Run").Return(fmt.Errorf("Failed")).Run(func(args mock.Arguments) {
RunCalled = true
})

return mockAppService, true
}

expected := -1
actual := app.CreateAndRunAppService("TestKey", mockFactory)
require.True(t, makeItRunCalled, "MakeItRun never called")
require.True(t, RunCalled, "Run never called")
assert.Equal(t, expected, actual)
}
12 changes: 6 additions & 6 deletions internal/app/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,19 +156,19 @@ func (svc *Service) AddBackgroundPublisherWithTopic(capacity int, topic string)
return pub, nil
}

// MakeItStop will force the service loop to exit in the same fashion as SIGINT/SIGTERM received from the OS
func (svc *Service) MakeItStop() {
// Stop will force the service loop to exit in the same fashion as SIGINT/SIGTERM received from the OS
func (svc *Service) Stop() {
if svc.ctx.stop != nil {
svc.ctx.stop()
} else {
svc.lc.Warn("MakeItStop called but no stop handler set on SDK - is the service running?")
svc.lc.Warn("Stop called but no stop handler set on SDK - is the service running?")
}
}

// MakeItRun initializes and starts the trigger as specified in the
// Run initializes and starts the trigger as specified in the
// configuration. It will also configure the webserver and start listening on
// the specified port.
func (svc *Service) MakeItRun() error {
func (svc *Service) Run() error {

config := container.ConfigurationFrom(svc.dic.Get)

Expand Down Expand Up @@ -222,7 +222,7 @@ func (svc *Service) MakeItRun() error {
svc.lc.Info("Terminating signal received: " + signalReceived.String())

case <-runCtx.Done():
svc.lc.Info("Terminating: svc.MakeItStop called")
svc.lc.Info("Terminating: svc.Stop called")
}

svc.ctx.stop = nil
Expand Down
6 changes: 3 additions & 3 deletions internal/app/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ func TestSetServiceKey(t *testing.T) {
}
}

func TestMakeItStop(t *testing.T) {
func TestStop(t *testing.T) {
stopCalled := false

sdk := Service{
Expand All @@ -779,11 +779,11 @@ func TestMakeItStop(t *testing.T) {
lc: logger.NewMockClient(),
}

sdk.MakeItStop()
sdk.Stop()
require.True(t, stopCalled, "Cancel function set at svc.stop should be called if set")

sdk.ctx.stop = nil
sdk.MakeItStop() //should avoid nil pointer
sdk.Stop() //should avoid nil pointer
}

func TestFindMatchingFunction(t *testing.T) {
Expand Down
38 changes: 19 additions & 19 deletions pkg/interfaces/mocks/ApplicationService.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions pkg/interfaces/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ type ApplicationService interface {
AddFunctionsPipelineForTopics(id string, topic []string, transforms ...AppFunction) error
// RemoveAllFunctionPipelines removes all existing function pipelines
RemoveAllFunctionPipelines()
// MakeItRun starts the configured trigger to allow the functions pipeline to execute when the trigger
// receives data and starts the internal webserver. This is a long running function which does not return until
// the service is stopped or MakeItStop() is called.
// An error is returned if the trigger can not be create or initialized or if the internal webserver
// Run starts the configured trigger to allow the functions pipeline to execute when the trigger
// receives data and starts the internal webserver. This is a long-running function which does not return until
// the service is stopped or Stop() is called.
// An error is returned if the trigger can not be created or initialized or if the internal webserver
// encounters an error.
MakeItRun() error
// MakeItStop stops the configured trigger so that the functions pipeline no longer executes.
Run() error
// Stop stops the configured trigger so that the functions pipeline no longer executes.
// An error is returned
MakeItStop()
Stop()
// RegisterCustomTriggerFactory registers a trigger factory for a custom trigger to be used.
RegisterCustomTriggerFactory(name string, factory func(TriggerConfig) (Trigger, error)) error
// RegisterCustomStoreFactory registers a factory function that can be used to create a custom storage client for the Store & Forward loop.
Expand Down

0 comments on commit 7915819

Please sign in to comment.