-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an endpoint to get aggregate statistics for a workflow
This can be used to create the argo view https://argo.stanford.edu/report/workflow_grid without having to look at Solr.
- Loading branch information
Showing
4 changed files
with
124 additions
and
3 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# frozen_string_literal: true | ||
|
||
## | ||
# API for handling requests about the state of all objects in a workflow | ||
class StatusController < ApplicationController | ||
def show | ||
workflow_name = params.require(:workflow) | ||
@result = status_response(workflow_name) | ||
|
||
render json: { steps: @result } | ||
end | ||
|
||
private | ||
|
||
def status_response(workflow_name) | ||
tree = steps_for_workflow(workflow_name) | ||
xml = WorkflowTemplateService.template_for(workflow_name) | ||
processes = WorkflowParser.new(xml).processes | ||
step_names = processes.map(&:process) | ||
step_names.map do |process_name| | ||
{ name: process_name, object_status: tree.fetch(process_name, {}) } | ||
end | ||
end | ||
|
||
# Returns a hash of counts of objects in each step and status: | ||
# @example | ||
# {"start-accession"=>{"completed"=>1} | ||
def steps_for_workflow(workflow) | ||
counts = WorkflowStep.active.where(workflow: workflow).group(:process, :status).count | ||
{}.tap do |tree| | ||
counts.each do |(step, status), val| | ||
tree[step] ||= {} | ||
tree[step][status] = val | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,4 +25,6 @@ | |
get 'all_queued' | ||
end | ||
end | ||
|
||
get '/workflow/:workflow', to: 'status#show', defaults: { format: :json } | ||
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,70 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe 'Get the status for a workflow', type: :request do | ||
include XmlFixtures | ||
|
||
before do | ||
allow(WorkflowTemplateService).to receive(:template_for).and_return(workflow_create) | ||
end | ||
|
||
context 'for all workflows' do | ||
before do | ||
FactoryBot.create(:workflow_step, | ||
status: 'completed', | ||
active_version: true) | ||
|
||
FactoryBot.create(:workflow_step, | ||
status: 'completed', | ||
active_version: true) | ||
|
||
FactoryBot.create(:workflow_step, | ||
status: 'waiting', | ||
active_version: true) | ||
|
||
FactoryBot.create(:workflow_step, | ||
status: 'waiting', | ||
active_version: false) | ||
|
||
FactoryBot.create(:workflow_step, | ||
status: 'error', | ||
process: 'descriptive-metadata', | ||
active_version: true) | ||
|
||
FactoryBot.create(:workflow_step, | ||
status: 'error', | ||
process: 'descriptive-metadata', | ||
active_version: true) | ||
|
||
FactoryBot.create(:workflow_step, | ||
status: 'waiting', | ||
process: 'descriptive-metadata', | ||
active_version: true) | ||
end | ||
|
||
it 'displays the counts' do | ||
get '/workflow/accessionWF' | ||
expect(response).to be_successful | ||
expect(JSON.parse(response.body)).to eq( | ||
'steps' => [ | ||
{ 'name' => 'start-accession', | ||
'object_status' => { 'completed' => 2, 'waiting' => 1 } }, | ||
{ 'name' => 'descriptive-metadata', | ||
'object_status' => { 'error' => 2, 'waiting' => 1 } }, | ||
{ 'name' => 'rights-metadata', 'object_status' => {} }, | ||
{ 'name' => 'content-metadata', 'object_status' => {} }, | ||
{ 'name' => 'technical-metadata', 'object_status' => {} }, | ||
{ 'name' => 'remediate-object', 'object_status' => {} }, | ||
{ 'name' => 'shelve', 'object_status' => {} }, | ||
{ 'name' => 'publish', 'object_status' => {} }, | ||
{ 'name' => 'provenance-metadata', 'object_status' => {} }, | ||
{ 'name' => 'sdr-ingest-transfer', 'object_status' => {} }, | ||
{ 'name' => 'sdr-ingest-received', 'object_status' => {} }, | ||
{ 'name' => 'reset-workspace', 'object_status' => {} }, | ||
{ 'name' => 'end-accession', 'object_status' => {} } | ||
] | ||
) | ||
end | ||
end | ||
end |