micro/runtime/runtime.go

88 lines
1.7 KiB
Go
Raw Normal View History

2019-09-14 07:33:14 +03:00
// Package runtime is a service runtime manager
package runtime
import "time"
var (
// DefaultRuntime is default micro runtime
DefaultRuntime Runtime = NewRuntime()
)
2019-09-14 07:33:14 +03:00
// Runtime is a service runtime manager
type Runtime interface {
// Init initializes runtime
Init(...Option) error
2019-09-14 07:33:14 +03:00
// Registers a service
2019-09-24 20:32:35 +03:00
Create(*Service, ...CreateOption) error
// Remove a service
Delete(*Service) error
2019-10-29 15:29:21 +03:00
// Update the service in place
Update(*Service) error
// List the managed services
List() ([]*Service, error)
2019-09-14 07:33:14 +03:00
// starts the runtime
Start() error
2019-09-14 07:33:14 +03:00
// Shutdown the runtime
Stop() error
}
// Notifier is an update notifier
type Notifier interface {
// Notify publishes notification events
Notify() (<-chan Event, error)
// Close stops the notifier
Close() error
2019-09-14 07:33:14 +03:00
}
// EventType defines notification event
type EventType int
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 15:29:21 +03: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 15:29:21 +03: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-14 07:33:14 +03:00
}
// Service is runtime service
type Service struct {
// Name of the service
Name string
// url location of source
Source string
// Path to store source
Path string
// Exec command
Exec string
// Version of the service
Version string
2019-09-14 07:33:14 +03:00
}