Drop per-task port blocks; previews use any free loopback port
This commit is contained in:
+12
-28
@@ -68,21 +68,16 @@ func loadMigrations() ([]migration, error) {
|
||||
return migrations, nil
|
||||
}
|
||||
|
||||
const (
|
||||
DefaultPortFirst = 41000
|
||||
PortBlock = 10
|
||||
TaskColors = 11
|
||||
)
|
||||
const TaskColors = 11
|
||||
|
||||
type Store struct {
|
||||
db *sql.DB
|
||||
path string
|
||||
portFirst int
|
||||
writeMu sync.Mutex
|
||||
onEvent func([]api.Event)
|
||||
db *sql.DB
|
||||
path string
|
||||
writeMu sync.Mutex
|
||||
onEvent func([]api.Event)
|
||||
}
|
||||
|
||||
func Open(path string, portFirst int, onEvent func([]api.Event)) (*Store, error) {
|
||||
func Open(path string, onEvent func([]api.Event)) (*Store, error) {
|
||||
dsn := "file:" + path + "?_pragma=journal_mode(WAL)&_pragma=busy_timeout(5000)&_pragma=foreign_keys(1)&_txlock=immediate"
|
||||
connector, err := newTracedConnector(dsn)
|
||||
if err != nil {
|
||||
@@ -96,7 +91,7 @@ func Open(path string, portFirst int, onEvent func([]api.Event)) (*Store, error)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Store{db: db, path: path, portFirst: portFirst, onEvent: onEvent}, nil
|
||||
return &Store{db: db, path: path, onEvent: onEvent}, nil
|
||||
}
|
||||
|
||||
func migrate(db *sql.DB, dataDir string) error {
|
||||
@@ -383,17 +378,6 @@ func (s *Store) CreateTask(ctx context.Context, t api.Task, frozen *FrozenWorkfl
|
||||
return ErrParentNotOpen
|
||||
}
|
||||
}
|
||||
if t.WorktreePath != "" {
|
||||
err := tx.QueryRowContext(ctx, `
|
||||
SELECT min(candidate) FROM (
|
||||
SELECT ? AS candidate
|
||||
UNION ALL SELECT port_base + ? FROM tasks WHERE status = ? AND port_base != 0
|
||||
) WHERE candidate NOT IN (SELECT port_base FROM tasks WHERE status = ?)
|
||||
`, s.portFirst, PortBlock, string(api.TaskStatusActive), string(api.TaskStatusActive)).Scan(&t.PortBase)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
err := tx.QueryRowContext(ctx, `
|
||||
WITH RECURSIVE palette(c) AS (SELECT 0 UNION ALL SELECT c + 1 FROM palette WHERE c + 1 < ?)
|
||||
SELECT c FROM palette
|
||||
@@ -404,9 +388,9 @@ func (s *Store) CreateTask(ctx context.Context, t api.Task, frozen *FrozenWorkfl
|
||||
return err
|
||||
}
|
||||
_, err = tx.ExecContext(ctx, `
|
||||
INSERT INTO tasks (id, project_id, title, merge_title, branch, worktree_path, base_ref, port_base, color, status, created_by, created_at, todo_item, forked_from, forked_at, workflow_name, workflow_definition_id, workflow_brief, workflow_title, workflow_stage, parent_task_id, audit)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`, t.Id, t.ProjectId, t.Title, mergeTitle, t.Branch, t.WorktreePath, t.BaseRef, t.PortBase, t.Color, string(t.Status), t.CreatedBy, formatTime(t.CreatedAt), todoItem, forkedFrom, forkedAt, workflowName, workflowDefinitionID, workflowBrief, workflowTitle, workflowStage, parentTaskID, audit)
|
||||
INSERT INTO tasks (id, project_id, title, merge_title, branch, worktree_path, base_ref, color, status, created_by, created_at, todo_item, forked_from, forked_at, workflow_name, workflow_definition_id, workflow_brief, workflow_title, workflow_stage, parent_task_id, audit)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`, t.Id, t.ProjectId, t.Title, mergeTitle, t.Branch, t.WorktreePath, t.BaseRef, t.Color, string(t.Status), t.CreatedBy, formatTime(t.CreatedAt), todoItem, forkedFrom, forkedAt, workflowName, workflowDefinitionID, workflowBrief, workflowTitle, workflowStage, parentTaskID, audit)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1673,7 +1657,7 @@ func (s *Store) ClearReviewRequests(ctx context.Context) error {
|
||||
|
||||
const projectColumns = `id, name, repo_path, default_branch, remote, created_by, created_at, review_workflow, audit_workflow`
|
||||
|
||||
const taskColumns = `id, project_id, title, merge_title, branch, worktree_path, base_ref, port_base, color, status, created_by, created_at, closed_at, merge_commit, todo_item, forked_from, forked_at, merge_queued_at, workflow_name, workflow_stage, parent_task_id, parent_merge_by, merge_after_review_by != '', state, merging_by != '' OR finalizing != '', discard_state != '' AND status = 'active', (SELECT coalesce(max(seq), 0) FROM events WHERE events.task_id = tasks.id AND kind = 'turn.ended' AND json_extract(payload, '$.summary') = 1), audit, ready, ` + backgroundExpr + `, ` + mergeFactsColumns
|
||||
const taskColumns = `id, project_id, title, merge_title, branch, worktree_path, base_ref, color, status, created_by, created_at, closed_at, merge_commit, todo_item, forked_from, forked_at, merge_queued_at, workflow_name, workflow_stage, parent_task_id, parent_merge_by, merge_after_review_by != '', state, merging_by != '' OR finalizing != '', discard_state != '' AND status = 'active', (SELECT coalesce(max(seq), 0) FROM events WHERE events.task_id = tasks.id AND kind = 'turn.ended' AND json_extract(payload, '$.summary') = 1), audit, ready, ` + backgroundExpr + `, ` + mergeFactsColumns
|
||||
|
||||
// Keep the child lookup separate from the task itself so SQLite can use tasks_parent.
|
||||
const backgroundExpr = `(audit != '' OR EXISTS (SELECT 1 FROM tasks r WHERE r.id = tasks.parent_task_id AND tasks.workflow_stage != '' AND r.audit != ''))
|
||||
@@ -1716,7 +1700,7 @@ func scanTask(row scanner) (api.Task, error) {
|
||||
ready := ""
|
||||
participants := ""
|
||||
f := &t.MergeFacts
|
||||
err := row.Scan(&t.Id, &t.ProjectId, &t.Title, &t.MergeTitle, &t.Branch, &t.WorktreePath, &t.BaseRef, &t.PortBase, &t.Color, &status, &t.CreatedBy, &createdAt, &closedAt, &mergeCommit, &todoItem, &forkedFrom, &forkedAt, &mergeQueuedAt, &workflowName, &workflowStage, &parentTaskID, &parentMergeBy, &t.MergeAfterReview, &taskState, &t.Merging, &t.Discarding, &t.SummarySeq, &audit, &ready, &t.Background,
|
||||
err := row.Scan(&t.Id, &t.ProjectId, &t.Title, &t.MergeTitle, &t.Branch, &t.WorktreePath, &t.BaseRef, &t.Color, &status, &t.CreatedBy, &createdAt, &closedAt, &mergeCommit, &todoItem, &forkedFrom, &forkedAt, &mergeQueuedAt, &workflowName, &workflowStage, &parentTaskID, &parentMergeBy, &t.MergeAfterReview, &taskState, &t.Merging, &t.Discarding, &t.SummarySeq, &audit, &ready, &t.Background,
|
||||
&f.UnmergedCommits, &f.UnmergedFiles, &f.UnreviewedChanges, &f.ReviewSnapshot, &f.ReviewCount, &f.ReviewRunning, &f.ReviewFailed, &f.ReviewFindings, &participants)
|
||||
if err != nil {
|
||||
return t, err
|
||||
|
||||
Reference in New Issue
Block a user