Documentation
¶
Index ¶
- Variables
- func NewAPIStorage(client *WorkerAPIClient) storage.Storage
- type SyncContext
- type Worker
- func (w *Worker) Deregister(ctx context.Context)
- func (w *Worker) GetMetrics() (cpu, mem float64)
- func (w *Worker) IsDraining() bool
- func (w *Worker) ReleaseAllLeases(ctx context.Context)
- func (w *Worker) RequestShutdown(id string)
- func (w *Worker) SelfRegister(ctx context.Context) error
- func (w *Worker) SetAdmissionThresholds(cpu, mem float64)
- func (w *Worker) SetLeaseTTL(ttlSeconds int)
- func (w *Worker) SetMetrics(cpu, mem float64)
- func (w *Worker) SetRegistrationInfo(name, host string, port int, description string)
- func (w *Worker) SetShutdownFunc(fn context.CancelFunc)
- func (w *Worker) SetStorage(s storage.Storage)
- func (w *Worker) SetSyncInterval(d time.Duration)
- func (w *Worker) SetWorkerCacheTTL(d time.Duration)
- func (w *Worker) SetWorkerConfig(workerID, totalWorkers int, workerGUID string, workerToken string)
- func (w *Worker) Start(ctx context.Context) (err error)
- func (w *Worker) SyncWorkflow(ctx context.Context, wf storage.Workflow, sctx SyncContext)
- func (w *Worker) TriggerShutdown()
- type WorkerAPIClient
- func (c *WorkerAPIClient) AcquireWorkflowLease(ctx context.Context, workflowID, ownerID string, ttlSeconds int) (bool, error)
- func (c *WorkerAPIClient) CreateLog(ctx context.Context, log storage.Log) error
- func (c *WorkerAPIClient) CreateLogs(ctx context.Context, logs []storage.Log) error
- func (c *WorkerAPIClient) CreateWorker(ctx context.Context, w storage.Worker) error
- func (c *WorkerAPIClient) DeleteWorker(ctx context.Context, id string) error
- func (c *WorkerAPIClient) GetSink(ctx context.Context, id string) (storage.Sink, error)
- func (c *WorkerAPIClient) GetSource(ctx context.Context, id string) (storage.Source, error)
- func (c *WorkerAPIClient) GetWorker(ctx context.Context, id string) (storage.Worker, error)
- func (c *WorkerAPIClient) GetWorkflow(ctx context.Context, id string) (storage.Workflow, error)
- func (c *WorkerAPIClient) ListSinks(ctx context.Context, filter storage.CommonFilter) ([]storage.Sink, int, error)
- func (c *WorkerAPIClient) ListSources(ctx context.Context, filter storage.CommonFilter) ([]storage.Source, int, error)
- func (c *WorkerAPIClient) ListWorkers(ctx context.Context, filter storage.CommonFilter) ([]storage.Worker, int, error)
- func (c *WorkerAPIClient) ListWorkflows(ctx context.Context, filter storage.CommonFilter) ([]storage.Workflow, int, error)
- func (c *WorkerAPIClient) Ping(ctx context.Context) error
- func (c *WorkerAPIClient) ReleaseWorkflowLease(ctx context.Context, workflowID, ownerID string) error
- func (c *WorkerAPIClient) RenewWorkflowLease(ctx context.Context, workflowID, ownerID string, ttlSeconds int) (bool, error)
- func (c *WorkerAPIClient) UpdateSink(ctx context.Context, snk storage.Sink) error
- func (c *WorkerAPIClient) UpdateSource(ctx context.Context, src storage.Source) error
- func (c *WorkerAPIClient) UpdateWorkerHeartbeat(ctx context.Context, id string, cpu, mem float64) error
- func (c *WorkerAPIClient) UpdateWorkflow(ctx context.Context, wf storage.Workflow) error
- func (c *WorkerAPIClient) UpdateWorkflowStats(ctx context.Context, id string, processed, errors, lag uint64) error
- func (c *WorkerAPIClient) UpdateWorkflowStatus(ctx context.Context, id string, status string) error
- type WorkerStorage
Constants ¶
This section is empty.
Variables ¶
var ErrPlatformConfig = errors.New("platform-url configuration error")
ErrPlatformConfig marks errors that stem from a misconfigured platform-url (empty, unparsable, unsupported scheme, or a scheme that disagrees with what the origin serves). These are deterministic — retrying will not help — so callers should fail fast rather than loop. Transient reachability failures are NOT wrapped with this sentinel.
Functions ¶
func NewAPIStorage ¶
func NewAPIStorage(client *WorkerAPIClient) storage.Storage
NewAPIStorage wraps a platform API client so it satisfies storage.Storage. It lets a remote worker's registry resolve sources, sinks and workflows from the platform API when no local database is available.
Types ¶
type SyncContext ¶
type Worker ¶
type Worker struct {
// contains filtered or unexported fields
}
Worker syncs the state of workflows from storage to the registry.
func NewWorker ¶
func NewWorker(storage WorkerStorage, registry *registry.Registry) *Worker
NewWorker creates a new worker.
func (*Worker) Deregister ¶
Deregister removes the worker entry from storage.
func (*Worker) GetMetrics ¶
GetMetrics returns the worker's current resource usage metrics.
func (*Worker) IsDraining ¶
IsDraining reports whether a graceful shutdown has been requested.
func (*Worker) ReleaseAllLeases ¶
ReleaseAllLeases releases all workflow leases held by this worker.
func (*Worker) RequestShutdown ¶
RequestShutdown asks this worker to begin a graceful shutdown if the given id matches its own GUID. It is safe to call concurrently and is a no-op for a different identity.
func (*Worker) SelfRegister ¶
SelfRegister registers the worker in the storage if it doesn't already exist.
func (*Worker) SetAdmissionThresholds ¶
SetAdmissionThresholds overrides this worker's load-shedding thresholds. Zero or negative leaves the process-wide setting in place.
The process-wide values come from the environment and are read once at startup, which is the right shape for an operator setting and the wrong one for anything that needs to differ per worker — a worker sized for bursty CDC wants different headroom from one polling a few APIs, and a test exercising lease failover wants no shedding at all. Passing 1 or above disables that dimension, the same escape hatch the environment variables offer.
func (*Worker) SetLeaseTTL ¶
SetLeaseTTL allows configuring the lease TTL in seconds (default 30).
func (*Worker) SetMetrics ¶
SetMetrics updates the worker's current resource usage metrics.
func (*Worker) SetRegistrationInfo ¶
SetRegistrationInfo sets the information used for self-registration.
func (*Worker) SetShutdownFunc ¶
func (w *Worker) SetShutdownFunc(fn context.CancelFunc)
SetShutdownFunc registers a callback used to stop the host process after the worker has gracefully drained. It is typically the application's context cancel function so a dedicated worker process exits cleanly.
func (*Worker) SetStorage ¶
SetStorage updates the worker's storage backend.
func (*Worker) SetSyncInterval ¶
SetSyncInterval sets how often the worker reconciles workflows from storage.
func (*Worker) SetWorkerCacheTTL ¶
SetWorkerCacheTTL sets the TTL for the worker sharding cache.
func (*Worker) SetWorkerConfig ¶
SetWorkerConfig sets the worker sharding configuration and optional GUID and Token.
func (*Worker) SyncWorkflow ¶
func (*Worker) TriggerShutdown ¶
func (w *Worker) TriggerShutdown()
TriggerShutdown invokes the registered shutdown callback, if any, to stop the host process. It is called after the worker has drained.
type WorkerAPIClient ¶
WorkerAPIClient handles communication with the Hermod platform API.
func NewWorkerAPIClient ¶
func NewWorkerAPIClient(baseURL string, token string) *WorkerAPIClient
func (*WorkerAPIClient) AcquireWorkflowLease ¶
func (c *WorkerAPIClient) AcquireWorkflowLease(ctx context.Context, workflowID, ownerID string, ttlSeconds int) (bool, error)
Lease APIs for the platform-backed client. The platform does not yet expose dedicated lease endpoints; for an API-backed remote worker, assignment is already enforced by matching wf.WorkerID against the worker's GUID (see isWorkflowAssigned). In that model there is no separate lease backend that can be "lost", so acquire/renew report the lease as owned. Returning false here would make leaseRenewalLoop interpret every tick as "lease lost" and repeatedly tear down healthy engines (closing CDC sources), which is the worst possible default. Treating "no lease backend" as "always owned" keeps engines stable while remaining safe because real ownership is enforced by the explicit worker assignment.
func (*WorkerAPIClient) CreateLogs ¶
CreateLogs ships a batch of workflow logs to the platform.
A remote worker has no database, so its engines' logs exist only in its own process output unless they travel here — which is exactly the deployment where reading a worker's console is hardest. This used to be a no-op, and every workflow log a remote worker produced was accepted and discarded.
A platform that predates the batch route answers 404. Workers and platforms are upgraded separately, so fall back to the per-log endpoint rather than going silent for the duration of a rollout.
func (*WorkerAPIClient) CreateWorker ¶
func (*WorkerAPIClient) DeleteWorker ¶
func (c *WorkerAPIClient) DeleteWorker(ctx context.Context, id string) error
func (*WorkerAPIClient) GetWorkflow ¶
func (*WorkerAPIClient) ListSinks ¶
func (c *WorkerAPIClient) ListSinks(ctx context.Context, filter storage.CommonFilter) ([]storage.Sink, int, error)
func (*WorkerAPIClient) ListSources ¶
func (c *WorkerAPIClient) ListSources(ctx context.Context, filter storage.CommonFilter) ([]storage.Source, int, error)
func (*WorkerAPIClient) ListWorkers ¶
func (c *WorkerAPIClient) ListWorkers(ctx context.Context, filter storage.CommonFilter) ([]storage.Worker, int, error)
func (*WorkerAPIClient) ListWorkflows ¶
func (c *WorkerAPIClient) ListWorkflows(ctx context.Context, filter storage.CommonFilter) ([]storage.Workflow, int, error)
func (*WorkerAPIClient) Ping ¶
func (c *WorkerAPIClient) Ping(ctx context.Context) error
Ping performs a one-shot connectivity check against the platform API's /healthz endpoint. It returns an actionable error for the common misconfigurations — most notably a platform-url whose scheme does not match what the origin actually serves — so the worker can fail fast at startup instead of silently failing every sync cycle (see sync.go).
func (*WorkerAPIClient) ReleaseWorkflowLease ¶
func (c *WorkerAPIClient) ReleaseWorkflowLease(ctx context.Context, workflowID, ownerID string) error
func (*WorkerAPIClient) RenewWorkflowLease ¶
func (*WorkerAPIClient) UpdateSink ¶
func (*WorkerAPIClient) UpdateSource ¶
func (*WorkerAPIClient) UpdateWorkerHeartbeat ¶
func (*WorkerAPIClient) UpdateWorkflow ¶
func (*WorkerAPIClient) UpdateWorkflowStats ¶
func (*WorkerAPIClient) UpdateWorkflowStatus ¶
type WorkerStorage ¶
type WorkerStorage interface {
GetWorker(ctx context.Context, id string) (storage.Worker, error)
CreateWorker(ctx context.Context, worker storage.Worker) error
ListWorkflows(ctx context.Context, filter storage.CommonFilter) ([]storage.Workflow, int, error)
GetWorkflow(ctx context.Context, id string) (storage.Workflow, error)
UpdateWorkflow(ctx context.Context, wf storage.Workflow) error
UpdateWorkflowStatus(ctx context.Context, id string, status string) error
UpdateWorkflowStats(ctx context.Context, id string, processed, errors, lag uint64) error
GetSource(ctx context.Context, id string) (storage.Source, error)
GetSink(ctx context.Context, id string) (storage.Sink, error)
ListSources(ctx context.Context, filter storage.CommonFilter) ([]storage.Source, int, error)
ListSinks(ctx context.Context, filter storage.CommonFilter) ([]storage.Sink, int, error)
ListWorkers(ctx context.Context, filter storage.CommonFilter) ([]storage.Worker, int, error)
UpdateSource(ctx context.Context, src storage.Source) error
UpdateSink(ctx context.Context, snk storage.Sink) error
UpdateWorkerHeartbeat(ctx context.Context, id string, cpu, mem float64) error
DeleteWorker(ctx context.Context, id string) error
CreateLog(ctx context.Context, log storage.Log) error
AcquireWorkflowLease(ctx context.Context, workflowID, ownerID string, ttlSeconds int) (bool, error)
RenewWorkflowLease(ctx context.Context, workflowID, ownerID string, ttlSeconds int) (bool, error)
ReleaseWorkflowLease(ctx context.Context, workflowID, ownerID string) error
}
WorkerStorage interface subset needed by worker.