-
Notifications
You must be signed in to change notification settings - Fork 0
/
component.go
62 lines (46 loc) · 2.41 KB
/
component.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2024 HUMAN Security.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package envite
import (
"context"
)
// Component defines the interface for an environment component.
// It includes methods for lifecycle management, configuration, and status reporting.
type Component interface {
// Type returns the type of the component.
Type() string
// AttachEnvironment associates the component with an environment and output writer.
// It allows the component to interact with its environment and handle output properly.
AttachEnvironment(ctx context.Context, env *Environment, writer *Writer) error
// Prepare readies the component for operation. This may involve pre-start configuration or checks.
Prepare(ctx context.Context) error
// Start initiates the component's operation.
// It should return any errors if encountered during startup.
Start(ctx context.Context) error
// Stop halts the component's operation.
// It should return any errors if encountered during stop.
Stop(ctx context.Context) error
// Cleanup performs any necessary cleanup operations for the component,
// such as removing temporary files or releasing external resources.
Cleanup(ctx context.Context) error
// Status reports the current operational status of the component.
Status(ctx context.Context) (ComponentStatus, error)
// Config returns the configuration of the component.
// The exact return type can vary between component types.
Config() any
}
// ComponentStatus represents the operational status of a component within the environment.
type ComponentStatus string
const (
// ComponentStatusStopped indicates that the component is not currently running.
ComponentStatusStopped ComponentStatus = "stopped"
// ComponentStatusFailed indicates that the component has encountered an error and cannot continue operation.
ComponentStatusFailed ComponentStatus = "failed"
// ComponentStatusStarting indicates that the component is in the process of starting up but is not yet fully operational.
ComponentStatusStarting ComponentStatus = "starting"
// ComponentStatusRunning indicates that the component is currently operational and running as expected.
ComponentStatusRunning ComponentStatus = "running"
// ComponentStatusFinished indicates that the component has completed its operation successfully and has stopped running.
ComponentStatusFinished ComponentStatus = "finished"
)