Initial buildout of worker pattern.
This commit is contained in:
95
worker.go
95
worker.go
@@ -1,18 +1,107 @@
|
||||
package honeybee
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Types
|
||||
|
||||
// Worker Implementation
|
||||
|
||||
type Worker interface{}
|
||||
type Worker interface {
|
||||
Start(
|
||||
ctx *WorkerContext,
|
||||
wg *sync.WaitGroup,
|
||||
)
|
||||
}
|
||||
|
||||
type WorkerContext struct {
|
||||
Inbox chan<- InboxMessage
|
||||
Events chan<- PoolEvent
|
||||
Errors chan<- error
|
||||
Stop <-chan struct{}
|
||||
PoolDone <-chan struct{}
|
||||
Logger *slog.Logger
|
||||
}
|
||||
|
||||
// Base Struct
|
||||
|
||||
type worker struct{}
|
||||
type worker struct {
|
||||
id string
|
||||
}
|
||||
|
||||
func (w *worker) runForwarder(
|
||||
messages <-chan []byte,
|
||||
inbox chan<- []byte,
|
||||
stop <-chan struct{},
|
||||
poolDone <-chan struct{},
|
||||
maxQueueSize int,
|
||||
) {
|
||||
}
|
||||
|
||||
// Initiator Worker
|
||||
|
||||
type InitiatorWorker struct{}
|
||||
type InitiatorWorker struct {
|
||||
*worker
|
||||
config *InitiatorWorkerConfig
|
||||
onReconnect func() (*Connection, error)
|
||||
}
|
||||
|
||||
func newInitiatorWorker(
|
||||
id string,
|
||||
config *InitiatorWorkerConfig,
|
||||
onReconnect func() (*Connection, error),
|
||||
logger *slog.Logger,
|
||||
|
||||
) (*InitiatorWorker, error) {
|
||||
w := &InitiatorWorker{
|
||||
worker: &worker{
|
||||
id: id,
|
||||
logger: logger,
|
||||
},
|
||||
config: config,
|
||||
onReconnect: onReconnect,
|
||||
}
|
||||
|
||||
return w, nil
|
||||
}
|
||||
|
||||
func (w *InitiatorWorker) Start(
|
||||
inbox chan<- InboxMessage,
|
||||
events chan<- PoolEvent,
|
||||
stop <-chan struct{},
|
||||
poolDone <-chan struct{},
|
||||
wg *sync.WaitGroup,
|
||||
) {
|
||||
}
|
||||
|
||||
func runReader(conn *Connection,
|
||||
messages chan<- []byte,
|
||||
heartbeat chan<- time.Time,
|
||||
reconnect chan<- struct{},
|
||||
newConn <-chan *Connection,
|
||||
stop <-chan struct{},
|
||||
poolDone <-chan struct{},
|
||||
|
||||
) {
|
||||
}
|
||||
|
||||
func runHealthMonitor(
|
||||
heartbeat <-chan time.Time,
|
||||
stop <-chan struct{},
|
||||
poolDone <-chan struct{},
|
||||
) {
|
||||
}
|
||||
|
||||
func runReconnector(
|
||||
reconnect <-chan struct{},
|
||||
newConn chan<- *Connection,
|
||||
stop <-chan struct{},
|
||||
poolDone <-chan struct{},
|
||||
) {
|
||||
}
|
||||
|
||||
// Responder Worker
|
||||
|
||||
|
||||
Reference in New Issue
Block a user