1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-12-18 08:26:38 +02:00
go-micro/runtime/runtime.go
Janos Dobronszki d2b6d35220
log.Errorf when pod streaming fails (#1463)
* log.Errorf when pod streaming fails

* Error method added for loggers

Co-authored-by: Asim Aslam <asim@aslam.me>
2020-04-01 23:03:26 +01:00

111 lines
2.2 KiB
Go

// Package runtime is a service runtime manager
package runtime
import (
"errors"
"time"
)
var (
// DefaultRuntime is default micro runtime
DefaultRuntime Runtime = NewRuntime()
// DefaultName is default runtime service name
DefaultName = "go.micro.runtime"
ErrAlreadyExists = errors.New("already exists")
)
// Runtime is a service runtime manager
type Runtime interface {
// String describes runtime
String() string
// Init initializes runtime
Init(...Option) error
// Create registers a service
Create(*Service, ...CreateOption) error
// Read returns the service
Read(...ReadOption) ([]*Service, error)
// Update the service in place
Update(*Service) error
// Remove a service
Delete(*Service) error
// List the managed services
List() ([]*Service, error)
// Start starts the runtime
Start() error
// Stop shuts down the runtime
Stop() error
// Logs
Logs(*Service, ...LogsOption) (LogStream, error)
}
// Stream returns a log stream
type LogStream interface {
Error() error
Chan() chan LogRecord
Stop() error
}
type LogRecord struct {
Message string
Metadata map[string]string
}
// Scheduler is a runtime service scheduler
type Scheduler interface {
// Notify publishes schedule events
Notify() (<-chan Event, error)
// Close stops the scheduler
Close() error
}
// 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
)
// 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"
}
}
// 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
}
// Service is runtime service
type Service struct {
// Name of the service
Name string
// Version of the service
Version string
// url location of source
Source string
// Metadata stores metadata
Metadata map[string]string
}