Documentation
¶
Overview ¶
Package taskworker is the single poll→execute→update loop shared by every worker flavour in the CLI: stdio workers, JavaScript (goja) workers, registry workers, and skill tool workers. It is layered — the loop and its two interfaces live here, the Conductor SDK is confined to the runner bridge, and each flavour's execution logic lives in a Handler.
Before this package existed the loop was hand-copied four times in cmd/worker.go with no backoff, no context cancellation, and no tests.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ToTaskResult ¶
func ToTaskResult(t Task, r Result, opts RunnerOptions) *model.TaskResult
ToTaskResult maps a Result onto the SDK's TaskResult. It is a pure function so the mapping — the part most likely to drift during a refactor — can be table-tested without a live client.
Types ¶
type Config ¶
type Config struct {
// PollBackoff is the wait after an empty or failed poll. Zero uses the default.
PollBackoff time.Duration
}
Config tunes the loop.
type GojaHandler ¶
type GojaHandler struct {
// contains filtered or unexported fields
}
GojaHandler runs a JavaScript worker in the CLI's embedded interpreter.
The program is compiled once and each task gets a fresh goja.Runtime: Runtimes are not safe for concurrent use, and a Handler is shared across the goroutines of a batch poll.
func NewGojaHandler ¶
func NewGojaHandler(script, name string) (*GojaHandler, error)
NewGojaHandler compiles script for repeated execution. name appears in stack traces.
type Handler ¶
Handler executes one task.
A Handler MUST be safe for concurrent use: one Handler is shared across all the goroutines of a batch poll.
type HandlerFunc ¶
HandlerFunc adapts a function to Handler.
type PolledTask ¶
type PolledTask struct {
Task Task
// Err is set when this task could not be converted from the SDK model. The loop
// fails such a task individually and continues with the rest of the batch.
Err error
}
PolledTask is one entry from a poll. Conversion happens per task so that a single malformed task fails on its own instead of discarding its whole batch.
type Result ¶
type Result struct {
Status Status `json:"status"`
Output map[string]interface{} `json:"output,omitempty"`
Logs []string `json:"logs,omitempty"`
Reason string `json:"reason,omitempty"`
}
Result is the outcome of executing one task.
There is no error return alongside it: every outcome is a Result, so there is exactly one way to express failure. Handlers build their own failure Results because the flavours shape failures differently — JavaScript workers report the message under an "error" output key, stdio workers use ReasonForIncompletion plus logs — and those differences are observable by workflows. The json tags exist because --verbose prints a Result back to the user, and that output was previously the stdio worker's own lowercase, omitempty-tagged shape.
type Runner ¶
type Runner interface {
Poll(ctx context.Context, taskType string) ([]PolledTask, error)
Update(ctx context.Context, t Task, r Result) error
}
Runner is the server boundary: polling for work and reporting results. The production implementation wraps the Conductor SDK; tests inject a fake.
func NewConductorRunner ¶
func NewConductorRunner(taskClient *client.TaskResourceApiService, opts RunnerOptions) Runner
NewConductorRunner returns a Runner backed by the Conductor task client, which the cmd layer supplies via internal.GetTaskClient().
type RunnerOptions ¶
type RunnerOptions struct {
WorkerID string
Domain string
Count int32
PollTimeoutMs int32
// UseTaskWorkerID reports the polled task's own worker id on the result instead of
// WorkerID. JavaScript workers behave this way and workflows can observe it.
UseTaskWorkerID bool
}
RunnerOptions carries the poll and reporting settings that the worker commands expose as flags. Each poll field is applied only when set, because always sending a field — an empty Workerid, for instance — would change the outgoing request.
type Status ¶
type Status string
Status is the task status reported back to Conductor. It is deliberately an open string type rather than a closed enum: JavaScript workers forward whatever status their script returns straight through, and FAILED_WITH_TERMINAL_ERROR is documented and in use. Handlers that need to constrain the set normalise it themselves.
type StdioHandler ¶
type StdioHandler struct {
// contains filtered or unexported fields
}
StdioHandler runs an external program per task: the full task JSON goes in on stdin, a result JSON comes back on stdout. It is safe for concurrent use — each Handle call builds its own command and buffers.
func NewStdioHandler ¶
func NewStdioHandler(opts StdioOptions) *StdioHandler
NewStdioHandler returns a Handler that executes opts.Command for each task.
type StdioOptions ¶
type StdioOptions struct {
// Command and Args are the worker program to run, once per task.
Command string
Args []string
// Env is appended to the child's environment. It is passed in rather than read from
// viper so this package does not depend on process-global config, and so tests can
// assert what the child receives without mutating global state.
Env []string
// Domain, when set, is exported to the child as POLL_DOMAIN.
Domain string
// ExecTimeout bounds a single task's execution. Zero means no timeout.
ExecTimeout time.Duration
// Verbose prints the task JSON and the result JSON to stdout.
Verbose bool
}
StdioOptions configures a StdioHandler.
type Task ¶
type Task struct {
ID string
WorkflowID string
Type string
// WorkerID is the worker id carried by the polled task. JavaScript workers report
// this value back on the result rather than the configured --worker-id.
WorkerID string
// Raw is json.Marshal(model.Task) — the whole task, not the raw HTTP body and not
// just inputData. Stdio workers write it to the child's stdin and goja workers
// expose it as $.task, so both depend on it being the SDK struct's marshalling.
Raw json.RawMessage
}
Task is one polled task, decoupled from the SDK's model.Task.
type Worker ¶
type Worker struct {
// contains filtered or unexported fields
}
Worker runs the poll→execute→update loop for a single task type over a Runner.
func (*Worker) Run ¶
Run polls taskType and dispatches each task to h until ctx is cancelled.
Cancellation is not immediate: Run returns once the in-flight batch finishes. A handler that blocks — a goja script has no interrupt wired, for instance — delays shutdown for as long as it runs.
Transient poll failures back off and retry rather than stop the loop, and a failing task affects only itself.