micro/runtime/runtime.go

111 lines
2.3 KiB
Go
Raw Normal View History

2019-09-13 21:33:14 -07:00
// Package runtime is a service runtime manager
package runtime
2020-01-18 02:13:24 +00:00
import (
"errors"
"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"
2020-01-18 02:13:24 +00:00
ErrAlreadyExists = errors.New("already exists")
)
2019-09-13 21:33:14 -07:00
// Runtime is a service runtime manager
type Runtime interface {
// Init initializes runtime
Init(...Option) error
// Create registers a service
2019-09-24 18:32:35 +01:00
Create(*Service, ...CreateOption) error
// Read returns the service
2019-11-29 11:35:00 +00:00
Read(...ReadOption) ([]*Service, error)
2019-10-29 12:29:21 +00:00
// Update the service in place
Update(*Service, ...UpdateOption) error
// Remove a service
Delete(*Service, ...DeleteOption) error
2020-04-12 23:41:21 +01:00
// Logs returns the logs for a service
Logs(*Service, ...LogsOption) (LogStream, error)
// Start starts the runtime
Start() error
// Stop shuts down the runtime
2019-09-13 21:33:14 -07:00
Stop() error
2020-04-12 23:41:21 +01:00
// String describes runtime
String() string
}
// Stream returns a log stream
type LogStream interface {
Error() error
Chan() chan LogRecord
Stop() error
}
type LogRecord struct {
Message string
Metadata map[string]string
2019-09-13 21:33:14 -07:00
}
2020-01-16 13:34:04 +00:00
// Scheduler is a runtime service scheduler
type Scheduler interface {
// Notify publishes schedule events
Notify() (<-chan Event, error)
2020-01-16 13:34:04 +00:00
// Close stops the scheduler
Close() error
2019-09-13 21:33:14 -07:00
}
2020-01-16 13:34:04 +00:00
// EventType defines schedule 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 12:29:21 +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
}
// Event is notification event
type Event struct {
2020-05-19 10:14:07 +01:00
// ID of the event
ID string
// Type is event type
Type EventType
// Timestamp is event timestamp
Timestamp time.Time
2020-05-19 10:14:07 +01:00
// Service the event relates to
Service *Service
// Options to use when processing the event
Options *CreateOptions
2019-09-13 21:33:14 -07: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
// url location of source
Source string
// Metadata stores metadata
Metadata map[string]string
2019-09-13 21:33:14 -07:00
}