Skip to content

feat: converge builders on *job.Definition (pkg/temporal/job consumer)#20

Merged
jasoet merged 12 commits into
mainfrom
feat/job-definition
May 11, 2026
Merged

feat: converge builders on *job.Definition (pkg/temporal/job consumer)#20
jasoet merged 12 commits into
mainfrom
feat/job-definition

Conversation

@jasoet

@jasoet jasoet commented May 11, 2026

Copy link
Copy Markdown
Owner

Summary

Consume the new pkg/temporal/job package and converge all four go-wf builders on producing *job.Definition. Removes datasync/workflow.FullJobRegistration and BuildJobRegistration.

What changed

Idempotency refactor (Tasks 12-13): container.RegisterAll and function.RegisterAll now route every workflow/activity registration through job.RegisterWorkflowOnce / job.RegisterActivityOnce. Multiple Definitions backing the same workflow type can safely call RegisterAll concurrently.

Builder convergence:

  • datasync/builder.SyncJobBuilder.Build() now returns (*job.Definition, error) (was (datasync.Job[T,U], error)).
  • datasync/chunk.ChunkedSync.Build() / DateChunkedSync.Build() now return (*job.Definition, error); schedule via new fluent setters .ScheduleEvery(d) / .ScheduleCron(expr) / .ScheduleRaw(spec).
  • function/builder.WorkflowBuilder and LoopBuilder collapsed to single Build() *job.Definition with mode setters .Pipeline() / .Parallel() / .Single() / .Loop() / .ParameterizedLoop() + identity setters .Name(string) / .TaskQueue(string) / .Activity(fn).
  • container/builder.WorkflowBuilder and LoopBuilder same shape, default task queue container-<name>. NewWorkflowBuilder() no longer takes name as first arg — use .Name(...).

Deletions:

  • datasync/workflow.FullJobRegistration (struct)
  • datasync/workflow.BuildJobRegistration (function)
  • All public BuildPipeline / BuildParallel / BuildSingle / BuildLoop / BuildParameterizedLoop / BuildDAG / BuildParameterizedDAG methods on the L1 builders (internal build*Input private helpers retained).

Examples updated (15 files) for the new temporal.NewClient 2-return signature, *job.Definition API, and chunk's new Build() (*job.Definition, error).

Spec

docs/superpowers/specs/2026-05-11-pkg-temporal-job-definition-design.md

Depends on

Test plan

  • task ci:test — 24 packages green
  • task test:integration — 24 packages green (real Temporal container)
  • task lint — clean
  • All 26 example files build under -tags=example

jasoet added 12 commits May 11, 2026 05:39
…flowOnce

Route all workflow and activity registrations through
job.RegisterWorkflowOnce / job.RegisterActivityOnce so that calling
RegisterAll (or RegisterWorkflows / RegisterActivities) more than once
on the same worker becomes a silent no-op instead of panicking with
"duplicate workflow type". Add TestRegisterAll_Idempotent to verify the
dedup mechanic end-to-end using the mock worker.
…lowOnce

Route all workflow and activity registrations through job.RegisterWorkflowOnce
and job.RegisterActivityOnce so that calling RegisterWorkflows, RegisterActivity,
or RegisterAll multiple times on the same worker is a no-op after the first call.

Change function signatures from the narrow WorkflowRegistrar interface to
worker.Worker (matching the container package pattern). Update worker_test.go
to use a mockWorker and add TestRegisterAll_Idempotent to verify dedup behaviour.
Replace datasync/builder Build() and datasync/chunk Build() return types
from datasync.Job[T,U]/FullJobRegistration to *job.Definition, and remove
the FullJobRegistration struct and BuildJobRegistration function from
datasync/workflow/sync.go. Update all test assertions accordingly.
Replace the single Schedule(time.Duration) setter on ChunkedSync and
DateChunkedSync with three typed setters: ScheduleEvery (interval),
ScheduleCron (cron expression), and ScheduleRaw (*job.ScheduleSpec).
The internal schedule field is now *job.ScheduleSpec directly, so
Build() passes it through without wrapping.
…eline()/.Parallel()/.Single()

WorkflowBuilder and LoopBuilder now expose Build() (*job.Definition, error) as the
primary entry point. Mode is selected via fluent setters (.Pipeline(), .Parallel(),
.Single() on WorkflowBuilder; .Loop()/.ParameterizedLoop() on LoopBuilder) instead
of separate Build* methods. Name and Activity are required before Build.

- WorkflowBuilder: remove public BuildPipeline/BuildParallel/BuildSingle; add
  Name, TaskQueue, Activity, Pipeline, Parallel, Single setters; add single Build
- LoopBuilder: add Name, TaskQueue, Activity, Loop, ParameterizedLoop setters;
  add single Build; keep BuildLoop/BuildParameterizedLoop for raw-input callers
- function/patterns: rewrite pipeline.go and parallel.go to build inputs directly
  without the now-removed Build* helpers
- examples/function: update builder.go to use new API; fix temporal.NewClient
  two-return-value signature across all example files
…peline()/.Parallel()/.Single()

Collapses the container WorkflowBuilder and LoopBuilder to match the
function builder pattern from Task 16: Name()/TaskQueue() fluent setters,
Pipeline()/Parallel()/Single() mode selectors, and a single Build() that
returns *job.Definition. Updates NewWorkflowBuilder() to accept only
BuilderOption args (name moved to .Name()). Keeps BuildPipeline/BuildParallel/
BuildSingle public for backward compatibility with patterns and callers that
need raw payload types. Adds LoopBuilder.Build() with Loop/ParameterizedLoop
mode inference from constructor. Updates patterns, examples accordingly.
Drop the removed io.Closer return from temporal.NewClient (3→2 values),
migrate datasync builder.go from dsworkflow.RegisterJob/BuildWorkflowInput
to def.Register/def.Execute, and handle the new 2-value Build() return in
chunk_basic.go using *job.Definition instead of FullJobRegistration.
@jasoet jasoet merged commit b308019 into main May 11, 2026
1 check passed
@jasoet jasoet deleted the feat/job-definition branch May 11, 2026 04:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant