Skip to content

Commit

Permalink
feat: add new view to list all playbooks than an agent can run
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
adityathebe committed Jan 17, 2024
1 parent 3ac11ac commit 097e733
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions models/playbooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const (
type PlaybookActionStatus string

const (
PlaybookActionStatusPending PlaybookActionStatus = "pending" // Waiting for a runner to pick it up
PlaybookActionStatusCompleted PlaybookActionStatus = "completed"
PlaybookActionStatusFailed PlaybookActionStatus = "failed"
PlaybookActionStatusRunning PlaybookActionStatus = "running"
Expand Down
22 changes: 22 additions & 0 deletions views/018_playbooks.sql
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,25 @@ CREATE OR REPLACE TRIGGER playbook_updated_trigger
AFTER UPDATE ON playbooks
FOR EACH ROW
EXECUTE PROCEDURE notify_playbook_update();

-- List of all the playbooks that can be run by an agent
CREATE OR REPLACE VIEW
playbooks_for_agent AS
WITH interim AS (
SELECT
id,
jsonb_array_elements_text(spec -> 'runsOn') AS agent_name
FROM
playbooks
WHERE
spec ->> 'runsOn' IS NOT NULL
)
SELECT
interim.agent_name,
agents.person_id,
agents.id as agent_id,
json_agg(interim.id) AS playbook_ids
FROM
interim
INNER JOIN agents ON interim.agent_name :: TEXT = agents.name
GROUP BY agent_name, agents.person_id, agent_id

0 comments on commit 097e733

Please sign in to comment.