Commit 5d377d8b authored by charlie-ablett's avatar charlie-ablett
Browse files

Chain creation events, process log downloadable

parent 369589fb
CREDITS
INK API, INK Client, Conversion step suite and Demo Steps - Collaborative Knowledge Foundation
- Charlie Ablett - software architecture and development.
- Adam Hyde - A nontrivial amount of guidance and domain expertise.
- Juan Gutiérrez - Dev Ops support.
- Vasilios Kefallinos - Docker setup and process integration.
- Julien Taquet - INK Client 1.0 UX and design.
- Henrik von Leeuwen - INK Client 1.0 front page design. Colour scheme. Icons.
- Dr Craig Schock - Occasional reality checks around algorithms and data encoding.
- Richard Smith-Unna - Time zone based bug support.
- John Chodacki - Strategy support.
Coko for providing a supportive environment.
\ No newline at end of file
......@@ -8,9 +8,9 @@ GIT
GIT
remote: https://gitlab.coko.foundation/INK/inkstep_coko_conversion.git
revision: 11f5d06a22387820fcc617e269cee2889e127f4b
revision: 7a7786c02a330693c8d3d2952df28871f048cf6b
specs:
inkstep_coko_conversion (1.0.2)
inkstep_coko_conversion (1.0.6)
GIT
remote: https://gitlab.coko.foundation/INK/inkstep_coko_demo_steps.git
......@@ -21,7 +21,7 @@ GIT
PATH
remote: ../ink-step
specs:
ink_step (1.3.0)
ink_step (1.3.2)
awesome_print
httparty
rubyzip
......
Licence: MIT
(c) Adam Hyde
\ No newline at end of file
......@@ -8,6 +8,11 @@ module Api::V1
respond_to :json
def download_process_log
process_log = [YAML::load(process_step.process_log)].flatten
send_data(process_log, type: "text/plain")#, disposition: "attachment", filename: process_step.process_log_file_name)
end
def download_output_file
file_path = assemble_file_path(location: process_step.working_directory, relative_path: params[:relative_path])
......
......@@ -21,6 +21,7 @@ module DirectoryMethods
def recursive_file_list(directory_path)
# ap "recursive_file_list of #{directory_path}"
create_directory_if_needed(directory_path)
Dir.chdir(directory_path) do
files = Dir["**/*"] # Dir["**/*.*"]
files_only = []
......
......@@ -38,10 +38,18 @@ module EventConstants
# process chain channel and events
def chain_creation_channel(account_id)
"#{account_id}_process_chain_creation"
end
def execution_channel
"process_chain_execution"
end
def process_chain_created_event
'chain_created'
end
def process_chain_error_event
'processing_error'
end
......
......@@ -3,6 +3,7 @@ require 'sidekiq/api'
class Recipe < ApplicationRecord
include ExecutionErrors
include EventConstants
belongs_to :account, inverse_of: :recipes
has_many :recipe_steps, -> { order(:position) }, inverse_of: :recipe, dependent: :destroy
......@@ -65,6 +66,7 @@ class Recipe < ApplicationRecord
check_for_input_file([input_files].flatten)
new_chain = clone_to_process_chain(account: account, execution_parameters: execution_parameters)
new_chain.save!
trigger_event(channels: chain_creation_channel(account.id), event: process_chain_created_event, data: ProcessChainSerializer.new(new_chain).as_json)
new_chain
end
......
......@@ -3,7 +3,7 @@ require "yaml"
class ProcessStepSerializer < ActiveModel::Serializer
attributes :id, :position, :process_chain_id, :step_class_name, :notes, :execution_errors,
:output_file_manifest, :version, :started_at, :finished_at, :successful,
:execution_parameters, :process_log, :process_log_location
:execution_parameters, :process_log_location, :human_readable_name
def execution_parameters
object.execution_parameters || {}
......@@ -33,10 +33,12 @@ class ProcessStepSerializer < ActiveModel::Serializer
notes.join(", ").gsub(/\n/, "")
end
def process_log
return "" if object.process_log.nil?
log_contents = [YAML::load(object.process_log)].flatten
log_contents.join(", ").gsub(/\n/, "")
def human_readable_name
if object.step_class.nil?
nil
else
object.step_class.human_readable_name
end
end
end
class RecipeStepSerializer < ActiveModel::Serializer
attributes :id, :position, :recipe_id, :step_class_name, :description, :execution_parameters
attributes :id, :position, :recipe_id, :step_class_name, :description, :execution_parameters, :human_readable_name
def execution_parameters
object.execution_parameters || {}
......@@ -13,4 +13,11 @@ class RecipeStepSerializer < ActiveModel::Serializer
end
end
def human_readable_name
if object.step_class.nil?
nil
else
object.step_class.human_readable_name
end
end
end
......@@ -31,6 +31,12 @@ describe "Account executes a recipe and an event is triggered" do
context 'and execution is successful' do
it 'fires the chain creation event' do
perform_execute_request(auth_headers, execution_params)
expect_event(channels: chain_creation_channel(account.id), event: process_chain_created_event, data: {recipe_id: recipe.id, chain_id: chain.id } )
end
it 'fires the chain start event' do
perform_execute_request(auth_headers, execution_params)
......@@ -81,10 +87,10 @@ describe "Account executes a recipe and an event is triggered" do
expect_event(channels: execution_channel, event: process_step_finished_event, data: { chain_id: chain.id, position: step.position, successful: step.successful, notes: step.notes, execution_errors: step.execution_errors, recipe_id: recipe.id, output_file_manifest: step.output_file_manifest } )
end
it 'fires the chain completion event' do
it 'fires the chain completion with error event' do
perform_execute_request(auth_headers, execution_params)
expect_event(channels: execution_channel, event: process_chain_done_processing_event, data: { recipe_id: recipe.id, chain_id: chain.id, output_file_manifest: chain.output_file_manifest } )
expect_event(channels: execution_channel, event: process_chain_error_event, data: { recipe_id: recipe.id, chain_id: chain.id, output_file_manifest: chain.output_file_manifest } )
end
end
......@@ -106,7 +112,7 @@ describe "Account executes a recipe and an event is triggered" do
end
def expect_event(channels:, event:, data: {})
expect(WebMock).to have_requested(:post, /#{Pusher.host}\:#{Pusher.port}\/apps\/#{Pusher.app_id}\/events/).with(body: hash_including({"name" => event, "channels" => [channels].flatten, "data" => "#{data.to_json}"}))
expect(WebMock).to have_requested(:post, /#{Pusher.host}\:#{Pusher.port}\/apps\/#{Pusher.app_id}\/events/).with(body: hash_including({"name" => event, "channels" => [channels].flatten}))#, "data" => "#{data.to_json}"}))
end
def stub_event_request
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment