runtime.go 1014 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package entities
  2. import (
  3. "time"
  4. )
  5. type (
  6. PluginRuntime struct {
  7. State PluginRuntimeState `json:"state"`
  8. Config PluginConfiguration `json:"config"`
  9. Connector PluginConnector `json:"-"`
  10. }
  11. PluginRuntimeInterface interface {
  12. InitEnvironment() error
  13. StartPlugin() error
  14. Stopped() bool
  15. Stop()
  16. Configuration() *PluginConfiguration
  17. }
  18. )
  19. func (r *PluginRuntime) Stopped() bool {
  20. return r.State.Stopped
  21. }
  22. func (r *PluginRuntime) Stop() {
  23. r.State.Stopped = true
  24. }
  25. func (r *PluginRuntime) Configuration() *PluginConfiguration {
  26. return &r.Config
  27. }
  28. type PluginRuntimeState struct {
  29. Restarts int `json:"restarts"`
  30. Active bool `json:"active"`
  31. RelativePath string `json:"relative_path"`
  32. ActiveAt *time.Time `json:"active_at"`
  33. DeadAt *time.Time `json:"dead_at"`
  34. Stopped bool `json:"stopped"`
  35. Verified bool `json:"verified"`
  36. }
  37. type PluginConnector interface {
  38. OnMessage(func([]byte))
  39. Read([]byte) int
  40. Write([]byte) int
  41. }