Documentation
¶
Overview ¶
Package task implements tasks, their status machine and dependencies.
Mutating functions take a *sql.Tx opened with BEGIN IMMEDIATE (db.DB.Tx); every status change is a compare-and-swap on tasks.version plus an events row in that tx.
Index ¶
- Constants
- Variables
- func AddDep(ctx context.Context, tx *sql.Tx, taskID, kind, on string, expectVersion int64, ...) error
- func CanTransition(from, to string) bool
- func RemoveDep(ctx context.Context, tx *sql.Tx, taskID, kind, on string, expectVersion int64, ...) error
- func SetCurrentRun(ctx context.Context, tx *sql.Tx, id, runID string) error
- func Terminal(s string) bool
- func ValidStatus(s string) bool
- type Actor
- type AddInput
- type Dep
- type DepRef
- type EditInput
- type Filter
- type Task
- func Add(ctx context.Context, tx *sql.Tx, in AddInput, actor Actor) (*Task, error)
- func Claim(ctx context.Context, tx *sql.Tx, id string, expectVersion int64, actor Actor) (*Task, error)
- func ClaimNext(ctx context.Context, tx *sql.Tx, projectID int64, actor Actor) (*Task, error)
- func ClaimWaiting(ctx context.Context, tx *sql.Tx, id string, expectVersion int64, actor Actor) (*Task, error)
- func Deliver(ctx context.Context, tx *sql.Tx, id, note string, expectVersion int64, ...) (*Task, error)
- func Edit(ctx context.Context, tx *sql.Tx, id string, in EditInput, actor Actor) (*Task, error)
- func Get(ctx context.Context, q db.Querier, id string) (*Task, error)
- func List(ctx context.Context, q db.Querier, f Filter) ([]Task, error)
- func Transition(ctx context.Context, tx *sql.Tx, id, to, reason string, expectVersion int64, ...) (*Task, error)
Constants ¶
const ( Draft = "draft" Ready = "ready" Claimed = "claimed" Running = "running" Waiting = "waiting" Review = "review" Done = "done" // finished, ready to deliver Delivered = "delivered" // handed over (`otag task deliver`); only from done Blocked = "blocked" Cancelled = "cancelled" )
Task statuses. DESIGN.md names: taslak, hazır, alındı, çalışıyor, soru_bekliyor, review, bitti, teslim edildi, engellendi, iptal.
Variables ¶
var DepKinds = []string{"blocks", "review_of", "parent", "related"}
DepKinds are the allowed dependency kinds.
var Statuses = []string{Draft, Ready, Claimed, Running, Waiting, Review, Done, Delivered, Blocked, Cancelled}
Statuses lists every status in lifecycle order.
Functions ¶
func AddDep ¶
func AddDep(ctx context.Context, tx *sql.Tx, taskID, kind, on string, expectVersion int64, actor Actor) error
AddDep adds edge taskID -> on of kind. For blocks, parent and review_of it rejects edges that would close a cycle. Adding an edge bumps the task's version (CAS against expectVersion when non-zero); an existing edge is a no-op.
func CanTransition ¶
CanTransition reports whether from -> to is allowed.
func RemoveDep ¶
func RemoveDep(ctx context.Context, tx *sql.Tx, taskID, kind, on string, expectVersion int64, actor Actor) error
RemoveDep deletes edge taskID -> on of kind and bumps the task's version (CAS against expectVersion when non-zero); a missing edge is a no-op.
func SetCurrentRun ¶
SetCurrentRun points a claimed task at the run working on it (CAS on version).
Types ¶
type Actor ¶
type Actor struct {
Name string // e.g. "user:enes" or "run:<id>"
RunID string
Source string // events.source; default "cli"
}
Actor identifies who performs a mutation; recorded on events.
type AddInput ¶
type AddInput struct {
ProjectID int64
Prefix string
Title string
Body string
Priority int
Profile string
Draft bool
ExternalRef string
Metadata json.RawMessage
ExtraPrompt string
Deps []DepRef
}
AddInput describes a new task.
type Dep ¶
type Dep struct {
Kind string `json:"kind"`
TaskID string `json:"task_id"`
Title string `json:"title"`
Status string `json:"status"`
}
Dep is one dependency edge as seen from a task.
type EditInput ¶
type EditInput struct {
Title *string
Body *string
Priority *int
Profile *string
ExternalRef *string
ExtraPrompt *string
Metadata json.RawMessage // replaces the whole object
MetaSet map[string]string // merged keys; values parsed as JSON when valid
AddDeps []DepRef
RemoveDeps []DepRef
ExpectVersion int64 // 0 = no check
}
EditInput lists optional changes; nil pointers are left untouched.
type Filter ¶
type Filter struct {
ProjectID int64 // 0 = all projects
Statuses []string
ReadyOnly bool // use the ready_tasks view (ready and unblocked)
Open bool // exclude done, delivered and cancelled
// Deliverable: done tasks waiting for delivery, without review tasks (they are
// delivered with the task they review).
Deliverable bool
// Recent orders by the last status change, newest first (instead of priority), so a
// Limit keeps the latest.
Recent bool
Limit int
}
Filter selects tasks for List.
type Task ¶
type Task struct {
ID string `json:"id"`
Project string `json:"project"`
ProjectID int64 `json:"-"`
Title string `json:"title"`
Body string `json:"body"`
Status string `json:"status"`
StatusReason string `json:"status_reason"`
Priority int `json:"priority"`
Profile string `json:"profile"`
CurrentRunID string `json:"current_run_id"`
Version int64 `json:"version"`
ExternalRef string `json:"external_ref"`
Metadata json.RawMessage `json:"metadata"`
ExtraPrompt string `json:"extra_prompt"`
ClaimedBy string `json:"claimed_by"`
ClaimedAt string `json:"claimed_at"`
StatusChangedAt string `json:"status_changed_at"`
ClosedAt string `json:"closed_at"`
DeliveredAt string `json:"delivered_at"`
CreatedBy string `json:"created_by"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
// Deps are edges from this task; Dependents are edges pointing at it. Filled by Get.
Deps []Dep `json:"deps,omitempty"`
Dependents []Dep `json:"dependents,omitempty"`
}
Task is a unit of work.
func Claim ¶
func Claim(ctx context.Context, tx *sql.Tx, id string, expectVersion int64, actor Actor) (*Task, error)
Claim atomically takes a ready, unblocked task. With id == "" it takes the highest-priority ready task of projectID. Exactly one concurrent caller wins; the others get CONFLICT.
func ClaimWaiting ¶
func ClaimWaiting(ctx context.Context, tx *sql.Tx, id string, expectVersion int64, actor Actor) (*Task, error)
ClaimWaiting takes over a waiting task whose run has ended (parked while its question is open, or ended without releasing the task) for the task's next run: waiting -> claimed. While a run of the task has not ended it is CONFLICT: that run owns the task. An open question stays open; its answer follows the task. `otag task claim` (Claim) still takes only ready tasks.
func Deliver ¶
func Deliver(ctx context.Context, tx *sql.Tx, id, note string, expectVersion int64, actor Actor) (*Task, error)
Deliver moves a done task to delivered (compare-and-swap) with delivered_at and a task.delivered event; note is kept as the status reason. The caller (run.Manager. DeliverTask) removes the task's worktrees after the commit.