-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #363 from roomorama/feature/improved-skip-stats
feature/improved-skip-stats
- Loading branch information
Showing
17 changed files
with
179 additions
and
40 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,14 @@ | ||
module Web::Controllers::SyncProcesses | ||
class Stats | ||
include Web::Action | ||
include Web::Controllers::InternalError | ||
|
||
expose :sync_process | ||
|
||
def call(params) | ||
@sync_process = SyncProcessRepository.find(params[:id]) | ||
|
||
halt 404 unless @sync_process | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<div class="content"> | ||
<h2>Sync Process Stats</h2> | ||
<pre class="highlight json code-block"> | ||
<%= pretty_print_json(sync_process.stats) %> | ||
</pre> | ||
</div> |
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,26 @@ | ||
module Web::Views::SyncProcesses | ||
class Stats | ||
include Web::View | ||
include Concierge::JSON | ||
|
||
def pretty_print_json(content) | ||
|
||
# uses the +pretty+ and +indent+ options provided by +Yajl::Encoder+ to | ||
# format the parsed JSON. Generates two line breaks per line (not for empty arrays) | ||
# to make the final content more readable. | ||
compact_empty_arrays( | ||
double_line_breaks Yajl::Encoder.encode(content.to_h, pretty: true, indent: " " * 2) | ||
) | ||
end | ||
|
||
private | ||
|
||
def double_line_breaks(str) | ||
str.gsub("\n", "\n\n") | ||
end | ||
|
||
def compact_empty_arrays(str) | ||
str.gsub(/\[\s*\]/, '[]') | ||
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
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
26 changes: 26 additions & 0 deletions
26
db/migrations/20160919094714_change_properties_skipped_stat.rb
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,26 @@ | ||
Hanami::Model.migration do | ||
up do | ||
SyncProcessRepository.of_type('metadata').each do |sync_record| | ||
stats = sync_record.stats.to_h | ||
stats['properties_skipped'] = [ | ||
{ | ||
'reason' => 'Unknown reason', | ||
'ids' => Array.new(stats['properties_skipped'], '') | ||
} | ||
] | ||
sync_record.stats = stats | ||
SyncProcessRepository.update(sync_record) | ||
end | ||
end | ||
|
||
down do | ||
SyncProcessRepository.of_type('metadata').each do |sync_record| | ||
stats = sync_record.stats.to_h | ||
stats['properties_skipped'] = stats['properties_skipped'].inject(0) do |res, ps| | ||
res + ps['ids'].length | ||
end | ||
sync_record.stats = stats | ||
SyncProcessRepository.update(sync_record) | ||
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
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 @@ | ||
require "spec_helper" | ||
require_relative '../../../../apps/web/views/sync_processes/stats' | ||
|
||
RSpec.describe Web::Views::SyncProcesses::Stats do | ||
include Support::Factories | ||
|
||
let(:metadata) { SyncProcessRepository.all.first } | ||
let(:exposures) { Hash[sync_process: metadata] } | ||
let(:template) { Hanami::View::Template.new('apps/web/templates/sync_processes/stats.html.erb') } | ||
let(:view) { described_class.new(template, exposures) } | ||
let(:rendered) { view.render } | ||
|
||
|
||
let(:sanitized) { rendered.gsub("\n", "").gsub(/\s\s+/, " ") } | ||
|
||
before do | ||
metadata_supplier = create_supplier(name: "Metadata Supplier") | ||
metadata_host = create_host(supplier_id: metadata_supplier.id, username: "metadata-host") | ||
|
||
create_sync_process(type: "metadata", successful: false, host_id: metadata_host.id, stats: { | ||
properties_created: 2, | ||
properties_updated: 10, | ||
properties_deleted: 1, | ||
properties_skipped: [ | ||
{ | ||
reason: 'Error 1', | ||
ids: ['314', '345'] | ||
} | ||
] | ||
}) | ||
end | ||
|
||
it "includes information about metadata sync processes" do | ||
expect(sanitized).to include %(: 2) # properties created | ||
expect(sanitized).to include %(: 10) # properties updated | ||
expect(sanitized).to include %(: 1) # properties deleted | ||
expect(sanitized).to include %(314) # skipped property | ||
end | ||
end |
Oops, something went wrong.