Add lead wake_on tool to wake the lead on a task's merge or discard
This commit is contained in:
@@ -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 := ""
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
CREATE TABLE lead_wakes (
|
||||
owner TEXT NOT NULL REFERENCES users(login),
|
||||
task_id TEXT NOT NULL REFERENCES tasks(id),
|
||||
created_at TEXT NOT NULL,
|
||||
PRIMARY KEY (owner, task_id)
|
||||
);
|
||||
Reference in New Issue
Block a user