2019-09-13 21:33:14 -07:00
|
|
|
// Package runtime is a service runtime manager
|
|
|
|
package runtime
|
|
|
|
|
2019-11-02 13:25:10 +00:00
|
|
|
import "time"
|
|
|
|
|
|
|
|
var (
|
|
|
|
// DefaultRuntime is default micro runtime
|
|
|
|
DefaultRuntime Runtime = NewRuntime()
|
2019-11-20 14:54:42 +00:00
|
|
|
// DefaultName is default runtime service name
|
|
|
|
DefaultName = "go.micro.runtime"
|
2019-11-02 13:25:10 +00:00
|
|
|
)
|
|
|
|
|
2019-09-13 21:33:14 -07:00
|
|
|
// Runtime is a service runtime manager
|
|
|
|
type Runtime interface {
|
2019-11-02 13:25:10 +00:00
|
|
|
// Init initializes runtime
|
|
|
|
Init(...Option) error
|
2019-11-15 13:41:40 +00:00
|
|
|
// Create registers a service
|
2019-09-24 18:32:35 +01:00
|
|
|
Create(*Service, ...CreateOption) error
|
2019-11-15 13:41:40 +00:00
|
|
|
// Get returns service or fails with error
|
|
|
|
Get(string, ...GetOption) ([]*Service, error)
|
2019-10-29 12:29:21 +00:00
|
|
|
// Update the service in place
|
|
|
|
Update(*Service) error
|
2019-11-15 13:41:40 +00:00
|
|
|
// Remove a service
|
|
|
|
Delete(*Service) error
|
2019-10-29 12:29:21 +00:00
|
|
|
// List the managed services
|
|
|
|
List() ([]*Service, error)
|
2019-11-15 13:41:40 +00:00
|
|
|
// Start starts the runtime
|
2019-09-13 21:58:03 -07:00
|
|
|
Start() error
|
2019-11-15 13:41:40 +00:00
|
|
|
// Stop shuts down the runtime
|
2019-09-13 21:33:14 -07:00
|
|
|
Stop() error
|
|
|
|
}
|
|
|
|
|
2019-11-02 13:25:10 +00:00
|
|
|
// Notifier is an update notifier
|
|
|
|
type Notifier interface {
|
|
|
|
// Notify publishes notification events
|
|
|
|
Notify() (<-chan Event, error)
|
|
|
|
// Close stops the notifier
|
|
|
|
Close() error
|
2019-09-13 21:33:14 -07:00
|
|
|
}
|
|
|
|
|
2019-11-02 13:25:10 +00:00
|
|
|
// EventType defines notification event
|
|
|
|
type EventType int
|
2019-09-13 21:58:03 -07:00
|
|
|
|
2019-11-02 13:25:10 +00:00
|
|
|
const (
|
|
|
|
// Create is emitted when a new build has been craeted
|
|
|
|
Create EventType = iota
|
|
|
|
// Update is emitted when a new update become available
|
|
|
|
Update
|
|
|
|
// Delete is emitted when a build has been deleted
|
|
|
|
Delete
|
|
|
|
)
|
2019-10-29 12:29:21 +00:00
|
|
|
|
2019-11-02 13:25:10 +00:00
|
|
|
// String returns human readable event type
|
|
|
|
func (t EventType) String() string {
|
|
|
|
switch t {
|
|
|
|
case Create:
|
|
|
|
return "create"
|
|
|
|
case Delete:
|
|
|
|
return "delete"
|
|
|
|
case Update:
|
|
|
|
return "update"
|
|
|
|
default:
|
|
|
|
return "unknown"
|
|
|
|
}
|
2019-10-29 12:29:21 +00:00
|
|
|
}
|
|
|
|
|
2019-11-02 13:25:10 +00:00
|
|
|
// Event is notification event
|
|
|
|
type Event struct {
|
|
|
|
// Type is event type
|
|
|
|
Type EventType
|
|
|
|
// Timestamp is event timestamp
|
|
|
|
Timestamp time.Time
|
|
|
|
// Service is the name of the service
|
|
|
|
Service string
|
|
|
|
// Version of the build
|
|
|
|
Version string
|
2019-09-13 21:33:14 -07:00
|
|
|
}
|
|
|
|
|
2019-11-02 13:25:10 +00:00
|
|
|
// Service is runtime service
|
|
|
|
type Service struct {
|
|
|
|
// Name of the service
|
|
|
|
Name string
|
2019-11-23 22:50:13 +00:00
|
|
|
// Version of the service
|
|
|
|
Version string
|
2019-11-02 13:25:10 +00:00
|
|
|
// url location of source
|
|
|
|
Source string
|
|
|
|
// Path to store source
|
|
|
|
Path string
|
|
|
|
// Exec command
|
2019-11-19 19:36:29 +00:00
|
|
|
Exec []string
|
2019-11-22 17:10:00 +00:00
|
|
|
// Metadata stores metadata
|
|
|
|
Metadata map[string]string
|
2019-09-13 21:33:14 -07:00
|
|
|
}
|