How fieldryand/goflow works
Purpose and Entry Points
Goflow is an embeddable Go DAG scheduler with a REST/SSE monitoring API and optional browser dashboard. Consumers construct an engine, register code-defined jobs, add middleware/handlers, then start the HTTP service through Goflow.Run. Core public construction and lifecycle are in goflow.go; a runnable usage reference is example/goflow-example.go.
Workflow Model and DAG Validation
A Job owns named Task nodes, schedule/active state, and dependency definitions. Tasks reference an Operator, retry policy, and trigger rule. DAG construction and dependency traversal/validation are centralized in job.go and dag.go; task state and execution settings live in task.go. The scheduler boundary is explicitly DAG-based: downstream work is released or skipped according to upstream outcomes and trigger rules.
Scheduling and Execution
The engine maintains registered jobs, applies cron schedules, accepts manual submissions, and coordinates concurrent runs. execution.go represents/persists job execution state, while goflow.go owns engine startup and job registration. A run executes ready tasks concurrently, records outcomes, retries failures using configured delays, and determines terminal job status from task results.
Operator Boundary
Operator is the extension point for actual workload execution: user-defined operators implement the execution contract, separating orchestration from domain work. Built-in command and HTTP operators are defined in operator.go; retry strategies and shared execution behavior are in utils.go. Operators may invoke local shell commands or external HTTP services, so task code is the primary boundary for side effects.
Persistence and Recovery
Execution history is stored through a pluggable gokv.Store; the default is in-memory, while callers can supply Redis, PostgreSQL-backed, S3, or other gokv-compatible storage. Persistence-facing execution logic is in execution.go, with engine store configuration in goflow.go. This enables history/recovery across restarts without coupling the scheduler to a specific database.
HTTP API, Streaming, and UI
Gin is the HTTP runtime. API routing covers health, job inspection/submission/schedule toggling, and execution queries in routes.go; the API contract is documented by swagger.json. Optional SSE streaming pushes execution updates to clients through stream.go. When configured with a UI path, Go serves the dashboard templates/assets from ui/html/index.html.tmpl, ui/html/job.html.tmpl, and the bundled frontend source ui/src/index.js.
Packaging and Deployment
The service runs as a single Go binary or container. Dockerfile defines image packaging, and .github/workflows/deploy-image.yml publishes deployment images. The example compose setup at example/docker-compose.yml demonstrates containerized operation with PostgreSQL-oriented integration.
Main entry points: execution.go Execution coordinator · goflow.go Goflow engine · routes.go Gin REST API · job.go Job & DAG model
Components 19
Scheduler Core
DAG orchestration and execution lifecycle.
- Goflow engine · Registers jobs, configures storage, and starts the service.
goflow.go - Job & DAG model · Owns tasks, dependencies, schedules, and validation.
job.go - DAG traversal · Determines dependency traversal and release eligibility.
dag.go - Task model · Defines operator, retry policy, and trigger rule.
task.go - Execution coordinator · Coordinates concurrent tasks, retries, and terminal status.
execution.go
Extensions & Storage
Workload and persistence boundaries.
- Operator boundary · Built-in command and HTTP operators execute task work.
operator.go - Retry behavior
utils.go - gokv store · Stores execution history for recovery across restarts.
- Shell / HTTP targets
Service Interface
HTTP monitoring, streaming, and dashboard.
- Gin REST API · Exposes health, jobs, submissions, schedules, and executions.
routes.go - API contract
swagger.json - SSE updates · Pushes execution updates to connected clients.
stream.go - Browser dashboard · Served when a UI path is configured.
ui/html/index.html.tmpl - Dashboard frontend
ui/src/index.js
Packaging
Container build and publishing.
- Container image
Dockerfile - Image publishing
.github/workflows/deploy-image.yml - Compose integration · Demonstrates PostgreSQL-oriented container operation.
example/docker-compose.yml
Other components
- Embedding consumer · Constructs and configures the engine.
- Runnable example
example/goflow-example.go
Connections 22
- Embedding consumer → Goflow engine: embeds and configures
- Runnable example → Goflow engine: demonstrates
- Goflow engine → Job & DAG model: registers
- Job & DAG model → DAG traversal: validates dependencies
- Job & DAG model → Task model: owns named tasks
- Goflow engine → Execution coordinator: schedules and submits runs
- Execution coordinator → DAG traversal: releases or skips downstream work
- Execution coordinator → Task model: runs ready tasks
- Task model → Operator boundary: selects workload
- Execution coordinator → Retry behavior: applies retry delays
- Operator boundary → Shell / HTTP targets: executes
- Execution coordinator → gokv store: persists run state
- Goflow engine → Gin REST API: starts HTTP service
- Gin REST API → API contract: documents
- Gin REST API → SSE updates: exposes updates
- Execution coordinator → SSE updates: publishes status changes
- Gin REST API → Browser dashboard: serves optionally
- Browser dashboard → Dashboard frontend: loads
- Container image → Goflow engine: packages service
- Image publishing → Container image: publishes
- Compose integration → Container image: runs
- Compose integration → gokv store: uses persistent backend