Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add context to Start, Init, Stop, and Finalize methods #5

Merged
merged 10 commits into from
Jan 1, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

## [Unreleased]

### Added

- Added `Finalize` support to `Process` interface. [#5](https://github.com/go-nacelle/process/pull/5)

### Changed

- Added context parameters to `Init`, `Start`, `Stop`, and `Finalize` methods. [#5](https://github.com/go-nacelle/process/pull/5)

## [v1.1.0] - 2020-10-03

### Added
Expand Down
16 changes: 10 additions & 6 deletions initializer.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package process

import "github.com/go-nacelle/config"
import (
"context"

"github.com/go-nacelle/config"
)

// Initializer is an interface that is called once on app
// startup.
Expand All @@ -10,7 +14,7 @@ type Initializer interface {
// files from disk, connecting to a remote service,
// initializing shared data structures, and inserting
// a service into a shared service container.
Init(config config.Config) error
Init(ctx context.Context, config config.Config) error
}

// Finalizer is an optional extension of an Initializer that
Expand All @@ -21,13 +25,13 @@ type Initializer interface {
type Finalizer interface {
// Finalize is called after the application has stopped
// all running processes.
Finalize() error
Finalize(ctx context.Context) error
}

// InitializerFunc is a non-struct version of an initializer.
type InitializerFunc func(config config.Config) error
type InitializerFunc func(ctx context.Context, config config.Config) error

// Init calls the underlying function.
func (f InitializerFunc) Init(config config.Config) error {
return f(config)
func (f InitializerFunc) Init(ctx context.Context, config config.Config) error {
return f(ctx, config)
}
28 changes: 16 additions & 12 deletions mocks/finalizer.go

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

30 changes: 17 additions & 13 deletions mocks/initializer.go

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

Loading