-
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 #367 from roomorama/release/0.10.0
Release/0.10.0
- Loading branch information
Showing
34 changed files
with
2,852 additions
and
105 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
module Workers | ||
module Suppliers | ||
module AtLeisure | ||
# +Workers::Suppliers::AtLeisure::Availabilities+ | ||
# | ||
# Performs properties availabilities synchronisation with supplier | ||
class Availabilities | ||
BATCH_SIZE = 50 | ||
|
||
attr_reader :synchronisation, :host | ||
|
||
def initialize(host) | ||
@host = host | ||
@synchronisation = Workers::CalendarSynchronisation.new(host) | ||
end | ||
|
||
def perform | ||
identifiers = all_identifiers | ||
|
||
identifiers.each_slice(BATCH_SIZE) do |ids| | ||
result = synchronisation.new_context { importer.fetch_availabilities(ids) } | ||
if result.success? | ||
availabilities = result.value | ||
availabilities.each do |availability| | ||
property_id = availability['HouseCode'] | ||
synchronisation.start(property_id) do | ||
next availability_error(availability) unless valid_availability?(availability) | ||
|
||
mapper.build(availability) | ||
end | ||
end | ||
else | ||
message = "Failed to perform the `#fetch_availabilities` operation, with properties: `#{ids}`" | ||
announce_error(message, result) | ||
end | ||
end | ||
synchronisation.finish! | ||
end | ||
|
||
private | ||
|
||
def availability_error(availability) | ||
property_id = availability['HouseCode'] | ||
error_message = availability['error'] | ||
message = "Error during fetching availabilities for property `#{property_id}`: `#{error_message}`" | ||
augment_context_error(message) | ||
|
||
Result.error(:availability_error) | ||
end | ||
|
||
def valid_availability?(availability) | ||
availability['error'].nil? | ||
end | ||
|
||
def all_identifiers | ||
PropertyRepository.from_host(host).only(:identifier).map(&:identifier) | ||
end | ||
|
||
def mapper | ||
@mapper ||= ::AtLeisure::Mappers::Calendar.new | ||
end | ||
|
||
def importer | ||
@importer ||= ::AtLeisure::Importer.new(credentials) | ||
end | ||
|
||
def credentials | ||
Concierge::Credentials.for(::AtLeisure::Client::SUPPLIER_NAME) | ||
end | ||
|
||
def augment_context_error(message) | ||
message = { | ||
label: 'Synchronisation Failure', | ||
message: message, | ||
backtrace: caller | ||
} | ||
context = Concierge::Context::Message.new(message) | ||
Concierge.context.augment(context) | ||
end | ||
|
||
def announce_error(message, result) | ||
augment_context_error(message) | ||
|
||
Concierge::Announcer.trigger(Concierge::Errors::EXTERNAL_ERROR, { | ||
operation: 'sync', | ||
supplier: ::AtLeisure::Client::SUPPLIER_NAME, | ||
code: result.error.code, | ||
context: Concierge.context.to_h, | ||
happened_at: Time.now | ||
}) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
# listen to supplier worker | ||
Concierge::Announcer.on('availabilities.AtLeisure') do |host, args| | ||
Workers::Suppliers::AtLeisure::Availabilities.new(host).perform | ||
Result.new({}) | ||
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
Oops, something went wrong.