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 ReopenReason(ctx context.Context, q db.Querier, taskID, runID string) (string, error)
- func SetBranch(ctx context.Context, tx *sql.Tx, id, branch string) (bool, 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 Push
- 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 RecordPush(ctx context.Context, tx *sql.Tx, id string, p Push, prev *Push, force bool, ...) (*Task, error)
- func Reopen(ctx context.Context, tx *sql.Tx, id, reason string, expectVersion int64, ...) (*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.
const ReviewNone = "none"
ReviewNone is the review override that disables review for a task.
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 ReopenReason ¶ added in v0.1.2
ReopenReason is the reason of the reopen the run after runID follows: the task.reopened event that names runID as the task's latest run ("" = the task's first run; "" result = none).
func SetBranch ¶ added in v0.1.2
SetBranch stores the task's branch the first time its worktree is created; a task that has one keeps it. It reports whether it stored it.
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
Base string // overrides the project's base ("" = the project's)
Review string // "" = the project's review_profile, ReviewNone, or a profile
}
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
// Base ("" = the project's again) is refused once the task has its worktree: the
// branch already starts there.
Base *string
// Review: "" = the project's review_profile again, ReviewNone, or a profile. It
// applies the next time the task finishes.
Review *string
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 Push ¶ added in v0.1.2
type Push struct {
Remote string `json:"remote"`
Branch string `json:"branch"`
SHA string `json:"sha"`
At string `json:"at"`
}
Push records the last push of a task branch (`otag task push`).
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"`
// Base overrides the project's base for this task ("" = the project's); frozen
// once the task has its worktree (Branch set).
Base string `json:"base"`
// Branch is the task's branch, stored when its worktree is first created and used
// from then on ("" = no worktree yet, or a same-mode project).
Branch string `json:"branch"`
// Review overrides the project's review_profile: "" = the project's, ReviewNone =
// no review, else a profile.
Review string `json:"review"`
// Push is the last `otag task push` (nil = never pushed).
Push *Push `json:"push"`
// 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.
func List ¶
List returns tasks ordered by priority then age (Filter.Recent: newest status change first).
func RecordPush ¶ added in v0.1.2
func RecordPush(ctx context.Context, tx *sql.Tx, id string, p Push, prev *Push, force bool, actor Actor) (*Task, error)
RecordPush stores a push of the task's branch and records task.pushed. prev is the push record the pusher read before pushing: if another push was recorded meanwhile it is a retryable CONFLICT and nothing is recorded (the remote has one of the two commits; push again to record it).
func Reopen ¶ added in v0.1.2
func Reopen(ctx context.Context, tx *sql.Tx, id, reason string, expectVersion int64, actor Actor) (*Task, error)
Reopen moves a done task back to ready (compare-and-swap): the same worktree and branch get another run. reason is required; it becomes the status reason and is recorded on the task.reopened event with the task's latest run ("run"), which is the run the next attempt follows, so its prior-attempt summary carries the reason. closed_at is cleared (it is set again when the task is done again). A delivered task is not reopened, nor is a review task (reopen the task it reviews). The caller (run.Manager.Reopen) marks the task's reviews stale and retracts its done notice in the same transaction.