Execute task and getting output from rake

This commit is contained in:
Adam
2015-12-31 14:17:38 +01:00
parent ca91c3d16f
commit a41e997931
6 changed files with 45 additions and 5 deletions

View File

@@ -48,13 +48,34 @@ class ItemsController < ApplicationController
@error_message = ""
@error_message = "Format of CSV is wrong (CSV content is empty)" if params[:csv_content] == ""
csv_file = ItemsHelper::create_csv(CSV.parse(params[:csv_content]))
csv_parsed = CSV.parse(params[:csv_content])
csv_file = ItemsHelper::create_csv(csv_parsed)
@output = ""
begin
ENV["INPUT"] = csv_file.path
case params[:task]
when 'validate_items'
@output = ItemsHelper::execute_command("rake ribica:validate_items")
#ItemsHelper::execute_command("rake ribica:reindex")
when 'import_items'
@output = ItemsHelper::execute_command("rake ribica:import_items")
#ItemsHelper::execute_command("rake ribica:reindex")
when 'update_prices'
@output = ItemsHelper::execute_command("rake ribica:update_prices")
#ItemsHelper::execute_command("rake ribica:reindex")
else
@error_message = "There is no such task"
end
ensure
sleep 5
csv_file.unlink
end
@output = @output.join("<br/>")
render :template => "items/export_import"
end
end