Documentation
¶
Overview ¶
Package protocol defines the public NATS request/reply contract between the Packtrail engine and the remote services that implement workflow tasks.
This is the only package in the module intended to be imported by external projects. Everything under internal/ is private to the engine.
Index ¶
Constants ¶
const ( StatusOK = "ok" // task succeeded; Payload is the new shared context StatusError = "error" // task failed permanently (no retry requested) StatusRetry = "retry" // task asks the engine to retry per the node policy )
Task response status values.
Variables ¶
This section is empty.
Functions ¶
func Serve ¶
Serve subscribes a Handler to subject as a queue subscriber (queue group "packtrail-workers"), decoding TaskRequest and replying with TaskResponse. It is a convenience for task services and tests; the engine itself never calls it.
subject may contain NATS wildcards (e.g. "tasks.triage.*") so a single worker can serve every execution of a task. The returned subscription should be drained/unsubscribed by the caller when done.
func ServeNamespaced ¶
func ServeNamespaced(nc *nats.Conn, namespace, subject string, h Handler) (*nats.Subscription, error)
ServeNamespaced is like Serve but prepends namespace to subject, matching the convention used by the engine's built-in nats-task invoker. Use it for out-of-process workers so they subscribe to the right namespaced subject without having to construct it manually.
protocol.ServeNamespaced(nc, "packtrail", "tasks.triage.*", handler) // subscribes to "packtrail.tasks.triage.*"
Types ¶
type Handler ¶
type Handler func(ctx context.Context, req TaskRequest) (TaskResponse, error)
Handler implements the business logic of a single task. It receives the decoded request and returns a response. Returning a non-nil error is treated as a transient failure and reported to the engine as StatusRetry.
type TaskRequest ¶
type TaskRequest struct {
ExecutionID string `json:"execution_id"`
NodeID string `json:"node_id"`
Payload json.RawMessage `json:"payload"`
Attempt int `json:"attempt"`
Deadline time.Time `json:"deadline"`
}
TaskRequest is the envelope sent by the engine to a task subject via request/reply.
type TaskResponse ¶
type TaskResponse struct {
Status string `json:"status"`
Payload json.RawMessage `json:"payload,omitempty"`
Error string `json:"error,omitempty"`
}
TaskResponse is the envelope a task service returns to the engine.