task

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

View Source
var DepKinds = []string{"blocks", "review_of", "parent", "related"}

DepKinds are the allowed dependency kinds.

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

func CanTransition(from, to string) bool

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

func SetCurrentRun(ctx context.Context, tx *sql.Tx, id, runID string) error

SetCurrentRun points a claimed task at the run working on it (CAS on version).

func Terminal

func Terminal(s string) bool

Terminal reports whether s is a final status: no work is left. A done task still waits for its delivery (done -> delivered), which is not work.

func ValidStatus

func ValidStatus(s string) bool

ValidStatus reports whether s is a known status.

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 DepRef

type DepRef struct {
	Kind string
	On   string // task id
}

DepRef names a dependency edge from a new or edited 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 Add

func Add(ctx context.Context, tx *sql.Tx, in AddInput, actor Actor) (*Task, error)

Add creates a task in status ready (or draft) and records task.created.

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 ClaimNext

func ClaimNext(ctx context.Context, tx *sql.Tx, projectID int64, actor Actor) (*Task, error)

ClaimNext claims the next ready task of a project.

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 Edit

func Edit(ctx context.Context, tx *sql.Tx, id string, in EditInput, actor Actor) (*Task, error)

Edit updates task fields (not status) with a version check.

func Get

func Get(ctx context.Context, q db.Querier, id string) (*Task, error)

Get returns a task with its dependency edges.

func List

func List(ctx context.Context, q db.Querier, f Filter) ([]Task, error)

List returns tasks ordered by priority then age (Filter.Recent: newest status change first).

func Transition

func Transition(ctx context.Context, tx *sql.Tx, id, to, reason string, expectVersion int64, actor Actor) (*Task, error)

Transition moves a task to status `to` if the status machine allows it.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL