-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbus.go
More file actions
93 lines (78 loc) · 2.62 KB
/
Copy pathbus.go
File metadata and controls
93 lines (78 loc) · 2.62 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package deploykit
import (
"context"
"time"
)
// EventType identifies the kind of event flowing through the EventBus.
type EventType string
const (
EventServiceCreated EventType = "service.created"
EventServiceUpdated EventType = "service.updated"
EventServiceDeleted EventType = "service.deleted"
EventServiceStatusChanged EventType = "service.status.changed"
EventContainerCreated EventType = "container.created"
EventContainerDeleted EventType = "container.deleted"
EventDeploymentCreated EventType = "deployment.created"
EventDeploymentStarting EventType = "deployment.starting"
EventDeploymentHealthy EventType = "deployment.healthy"
EventDeploymentFailed EventType = "deployment.failed"
)
// Event is a single message broadcast on the EventBus.
// ProjectID is used by subscribers to filter per-project streams; leave empty
// for global events.
type Event struct {
Type EventType
ProjectID string
Payload any
At time.Time
}
// EventBus is an in-process publish/subscribe broker.
//
// Publish must be non-blocking — slow subscribers drop messages rather than
// backpressure the publisher.
type EventBus interface {
Publish(ctx context.Context, evt Event)
Subscribe(buffer int) Subscription
}
// Subscription is a single subscriber's receive channel. Close to unsubscribe
// and release resources; after Close the channel is closed.
type Subscription interface {
C() <-chan Event
Close()
}
// Event payload types.
type ServiceCreatedPayload struct {
Service *Service `json:"service"`
}
type ServiceUpdatedPayload struct {
Service *Service `json:"service"`
}
type ServiceDeletedPayload struct {
ServiceID string `json:"service_id"`
}
type ServiceStatusChangedPayload struct {
ServiceID string `json:"service_id"`
OldStatus string `json:"old_status"`
NewStatus string `json:"new_status"`
}
type ContainerCreatedPayload struct {
ServiceID string `json:"service_id"`
ContainerID string `json:"container_id"`
Status string `json:"status"`
}
type ContainerDeletedPayload struct {
ServiceID string `json:"service_id"`
ContainerID string `json:"container_id"`
}
type DeploymentCreatedPayload struct {
Deployment *Deployment `json:"deployment"`
}
// DeploymentStatusPayload covers deployment.starting / .healthy / .failed.
// FailureReason is set only for failed; AttemptCount is set for failed.
type DeploymentStatusPayload struct {
DeploymentID string `json:"deployment_id"`
ServiceID string `json:"service_id"`
Status string `json:"status"`
FailureReason *string `json:"failure_reason,omitempty"`
AttemptCount int `json:"attempt_count,omitempty"`
}