-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add steps API based on pre-existing run API
- Loading branch information
Showing
8 changed files
with
170 additions
and
227 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
defmodule LightningWeb.API.StepController do | ||
use LightningWeb, :controller | ||
|
||
alias Lightning.Invocation | ||
alias Lightning.Policies.Permissions | ||
alias Lightning.Policies.ProjectUsers | ||
alias Lightning.Projects | ||
|
||
action_fallback LightningWeb.FallbackController | ||
|
||
def index(conn, %{"project_id" => project_id} = params) do | ||
with :ok <- authorize_read(conn, project_id) do | ||
pagination_attrs = Map.take(params, ["page_size", "page"]) | ||
|
||
page = | ||
project_id | ||
|> Projects.get_project!() | ||
|> Invocation.list_steps_for_project(pagination_attrs) | ||
|
||
render(conn, "index.json", %{page: page, conn: conn}) | ||
end | ||
end | ||
|
||
def show(conn, %{"project_id" => project_id, "id" => id}) do | ||
with :ok <- authorize_read(conn, project_id) do | ||
step = Invocation.get_step_with_job!(id) | ||
render(conn, "show.json", %{step: step, conn: conn}) | ||
end | ||
end | ||
|
||
defp authorize_read(conn, project_id) do | ||
Permissions.can( | ||
ProjectUsers, | ||
:access_project, | ||
conn.assigns.current_resource, | ||
%{project_id: project_id} | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
defmodule LightningWeb.API.StepJSON do | ||
@moduledoc false | ||
|
||
# import LightningWeb.API.Helpers | ||
|
||
def render("index.json", %{page: page}) do | ||
page.entries | ||
|> Enum.map(&process_instance/1) | ||
# |> Enum.concat(pagination_links(conn, page)) | ||
end | ||
|
||
def render("show.json", %{step: step}) do | ||
process_instance(step) | ||
end | ||
|
||
defp process_instance(step) do | ||
%{ | ||
id: step.id, | ||
processRef: "#{step.job.name}:1:#{step.job.id}", | ||
initTime: step.started_at, | ||
state: step_state(step), | ||
lastChangeTime: step.updated_at | ||
} | ||
end | ||
|
||
defp step_state(step) do | ||
case {step.started_at, step.finished_at, step.exit_reason} do | ||
{nil, nil, _reason} -> "Ready" | ||
{_started_at, nil, _reason} -> "Active" | ||
{_started_at, _finished_at, "sucess"} -> "Completed" | ||
{_started_at, _finished_at, failed} when failed in ["cancel", "kill"] -> "Terminated" | ||
{_started_at, _finished_at, _reason} -> "Failed" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 0 additions & 130 deletions
130
test/lightning_web/controllers/api/run_controller_test.exs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.