Add lead wake_on tool to wake the lead on a task's merge or discard

This commit is contained in:
Ian Gulliver
2026-10-21 12:10:25 -07:00
parent 9ab1c0d079
commit 8c16bc3fb0
4 changed files with 101 additions and 4 deletions
+36
View File
@@ -101,6 +101,42 @@ func (s *Store) DeleteLeadInputs(ctx context.Context, ids []int64) error {
})
}
func (s *Store) AddLeadWake(ctx context.Context, owner, taskID string) error {
return s.write(ctx, func(tx *sql.Tx, emit emitFunc) error {
active := false
err := tx.QueryRowContext(ctx, `SELECT status = ? FROM tasks WHERE id = ?`, string(api.TaskStatusActive), taskID).Scan(&active)
if errors.Is(err, sql.ErrNoRows) || (err == nil && !active) {
return ErrNotFound
}
if err != nil {
return err
}
_, err = tx.ExecContext(ctx, `INSERT OR IGNORE INTO lead_wakes (owner, task_id, created_at) VALUES (?, ?, ?)`, owner, taskID, now())
return err
})
}
func (s *Store) TakeLeadWakes(ctx context.Context, taskID string) ([]string, error) {
owners := []string{}
err := s.write(ctx, func(tx *sql.Tx, emit emitFunc) error {
rows, err := tx.QueryContext(ctx, `DELETE FROM lead_wakes WHERE task_id = ? RETURNING owner`, taskID)
if err != nil {
return err
}
defer rows.Close()
for rows.Next() {
owner := ""
err = rows.Scan(&owner)
if err != nil {
return err
}
owners = append(owners, owner)
}
return rows.Err()
})
return owners, err
}
func (s *Store) GetFocus(ctx context.Context, login string) (api.Focus, error) {
f := api.Focus{}
raw := ""