Skip to content

Commit

Permalink
Merge pull request #529 from roomorama/release/1.0.0
Browse files Browse the repository at this point in the history
Release/1.0.0
  • Loading branch information
keang authored Nov 14, 2016
2 parents bb47e5f + 7d6a188 commit ed2720d
Show file tree
Hide file tree
Showing 75 changed files with 921 additions and 338 deletions.
25 changes: 23 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,29 @@ This file summarises the most important changes that went live on each release
of Concierge. Please check the Wiki entry on the release process to understand
how this file is formatted and how the process works.

## Unreleased
-
## [1.0.0]
### Fixed
- Avantio: add handling of `check_in_too_near` response code
- Avantio: mark first MARGIN = 3 days as unavailable

### Added
- Ciirus: add new spec for cancel action when `CancelBookingResponse` contains API error
- Concierge: support for `max_guests_exceeded` error for `Concierge::Errors::Quote`
- Kigo: add support for `check_in_too_far`
- Support for rendering flash messages in templates (flash[:notice] and flash[:error] are supported)
- UI button to resync host from supplier's hosts listning page
- UI form to add host

### Changed
- AtLeisure: rename `unsupported_on_request_reservation` to `property_not_instant_bookable`
- Ciirus: rename `unexpected_response` to `unrecognised_response` for booking and cancel
- SAW: use `unrecognised_response` instead of custom error codes coming from API
- RU: use `unrecognised_response` instead of custom error codes coming from API
- RU: use `max_guests_exceeded` instead of `unrecognised_response`
- Kigo: change `quote_call_failed` and `booking_call_failed` error codes to `unrecognized_response`
- Kigo: change `reservation_not_found`, `unavailable_dates` to `unrecognized_response`
- Poplidays: rename `invalid_property_error` to `property_not_instant_bookable`
- Poplidays: use `property_no_longer_available` instead of unavailable quotation when `http_status_409` is got

## [0.13.3] - 2016-11-10
### Fixed
Expand Down
4 changes: 4 additions & 0 deletions apps/web/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ class Application < Hanami::Application
include Hanami::Helpers
include Web::Assets::Helpers
end

controller.prepare do
expose :flash
end
end

configure :development do
Expand Down
19 changes: 19 additions & 0 deletions apps/web/assets/stylesheets/flash_messages.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.flash-message {
font-size: 0.9em;
color: #aaa;
padding: 20px;
background-color: #eee;
margin-bottom: 20px;
border: 1px solid #bbb;
text-align: center;
}

.flash-message.notice {
background-color: #2ebbab;
color: #fff;
}

.flash-message.error {
background-color: #e14536;
color: #fff;
}
8 changes: 8 additions & 0 deletions apps/web/assets/stylesheets/host_form.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.host-form .host-form-control {
padding: 5px;
}

.host-form .host-form-control label {
display: inline-block;
width: 150px;
}
6 changes: 4 additions & 2 deletions apps/web/config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
get "/sync_processes/:id/stats", to: "sync_processes#stats", as: :stats
post "/suppliers/worker_resync", to: "workers#resync", as: :worker_resync
get "/", to: "dashboard#index", as: :root

resources :errors, only: [:index, :show], controller: "external_errors"
resources :reservations, only: [:index]
resources :suppliers, only: [:show]
resources :suppliers, only: [:show] do
resources :hosts, only: [:new, :create], controller: "hosts"
end
resources :sync_processes, only: [:index]

52 changes: 52 additions & 0 deletions apps/web/controllers/hosts/create.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
module Web::Controllers::Hosts
class Create
include Web::Action

params do
param :supplier_id, type: String, presence: true
param :host do
param :identifier, type: String, presence: true
param :username, type: String, presence: true
param :access_token, type: String, presence: true
param :fee_percentage, type: Integer, presence: true
end
end

def call(params)
if params.valid?
host_creation = build_host_creation(params)
result = host_creation.perform

if result.success?
flash[:notice] = "Host was successfully created"
else
flash[:error] = "Host creation unsuccessful: #{result.error.code}"
end
else
flash[:error] = "Host parameters validation error"
end

redirect_to routes.supplier_path(params[:supplier_id])
end

private
def build_host_creation(params)
Concierge::Flows::HostCreation.new(
supplier: supplier,
identifier: params.get("host.identifier"),
username: params.get("host.username"),
access_token: params.get("host.access_token"),
fee_percentage: params.get("host.fee_percentage"),
config_path: config_path
)
end

def supplier
SupplierRepository.find(params[:supplier_id])
end

def config_path
Hanami.root.join("config", "suppliers.yml").to_s
end
end
end
11 changes: 11 additions & 0 deletions apps/web/controllers/hosts/new.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Web::Controllers::Hosts
class New
include Web::Action

expose :supplier

def call(params)
@supplier = SupplierRepository.find(params[:supplier_id])
end
end
end
32 changes: 32 additions & 0 deletions apps/web/controllers/workers/resync.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require_relative "../internal_error"

module Web::Controllers::Workers
class Resync
include Web::Action
include Web::Controllers::InternalError

def call(params)
worker = find_worker(params.get("worker.worker_id"))

if worker
if worker.idle?
Concierge::Flows::WorkerJobEnqueue.new(worker).perform

flash[:notice] = "#{worker.type} worker with id #{worker.id} was queued to synchronisation"
else
flash[:error] = "#{worker.type} worker with id #{worker.id} cannot be queued because it has #{worker.status} status"
end
else
flash[:error] = "Couldn't find requested worker"
end

redirect_to request.referer
end

private
def find_worker(worker_id)
BackgroundWorkerRepository.find(worker_id)
end

end
end
3 changes: 2 additions & 1 deletion apps/web/templates/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pure/0.6.0/pure-min.css">
<link href='https://fonts.googleapis.com/css?family=Source+Sans+Pro' rel='stylesheet' type='text/css'>
<%= stylesheet "dashboard", "external_errors" %>
<%= stylesheet "dashboard", "external_errors", "flash_messages" %>

<title>Concierge - Monitoring</title>
<%= favicon %>
Expand Down Expand Up @@ -34,6 +34,7 @@
</h1>
</div>

<%= render partial: 'components/flash_messages', locals: { flash: flash } %>
<%= yield %>
</div>
</div>
Expand Down
5 changes: 5 additions & 0 deletions apps/web/templates/components/_flash_messages.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<% if flash_message(flash) %>
<div class="flash-message <%= flash_message_type(flash) %>">
<%= flash_message(flash) %>
</div>
<% end %>
33 changes: 33 additions & 0 deletions apps/web/templates/hosts/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<%= stylesheet "host_form" %>

<div class="content">
<h2 class="content-subhead"><%= supplier.name %></h2>
<h3>Create new host</h3>
<%=
form_for :host, routes.supplier_hosts_path(supplier.id), class: 'host-form' do
div(class: 'host-form-control') do
label :identifier
text_field :identifier
end

div(class: 'host-form-control') do
label :username
text_field :username
end

div(class: 'host-form-control') do
label :access_token
text_field :access_token
end

div(class: 'host-form-control') do
label :fee_percentage
number_field :fee_percentage
end

div do
submit 'Create host'
end
end
%>
</div>
9 changes: 9 additions & 0 deletions apps/web/templates/suppliers/_workers_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<th>Worker</th>
<th>Status</th>
<th>Scheduled to Run At</th>
<th>Actions</th>
</tr>
</thead>

Expand All @@ -13,6 +14,14 @@
<td><%= worker.type %></td>
<td><%= status_label(worker.status) %></td>
<td><%= format_time(worker)%></td>
<td>
<%=
form_for :worker, routes.worker_resync_path do
hidden_field :worker_id, value: worker.id
submit 'Resync'
end
%>
</td>
</tr>
<% end %>
</tbody>
Expand Down
3 changes: 3 additions & 0 deletions apps/web/templates/suppliers/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
</p>

<h3>Hosts</h3>

<p><%= link_to "New Host", routes.new_supplier_host_path(supplier.id), class: "pure-button" %></p>

<table class="concierge-table pure-table pure-table-striped">
<thead>
<tr>
Expand Down
12 changes: 12 additions & 0 deletions apps/web/views/application_layout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@ module Web
module Views
class ApplicationLayout
include Web::Layout

def flash_message(flash)
type = flash_message_type(flash)
return nil unless type

flash[type]
end

def flash_message_type(flash)
return :notice if flash[:notice]
return :error if flash[:error]
end
end
end
end
5 changes: 5 additions & 0 deletions apps/web/views/hosts/new.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Web::Views::Hosts
class New
include Web::View
end
end
6 changes: 3 additions & 3 deletions apps/workers/processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ module Workers

# +Workers::Processor+
#
# This class wraps the logic of processing one message read from the +Workers::Queue+
# (backed by an SQS queue) class. By default (as specified by +Workers::Queue::Element+),
# This class wraps the logic of processing one message read from the +Concierge::Queue+
# (backed by an SQS queue) class. By default (as specified by +Concierge::Queue::Element+),
# each message is a JSON-encoded string containing two fields:
#
# +operation+ - the identifier of the operation to be performed. Only +sync+ is supported
Expand All @@ -16,7 +16,7 @@ module Workers
#
# Example
#
# queue = Workers::Queue.new(credentials)
# queue = Concierge::Queue.new(credentials)
# queue.poll do |message|
# Workers::Processor.new(message).process!
# end
Expand Down
6 changes: 3 additions & 3 deletions apps/workers/processor/master.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Workers::Processor
# +Workers::Processor::Master+
#
# This class is responsible to coordinate a set of worker processes that process
# messages from the SQS queue (+Workers::Queue+), and wait for more messages.
# messages from the SQS queue (+Concierge::Queue+), and wait for more messages.
# It is able to:
#
# * prefork a given number of worker processes, given on initialization
Expand Down Expand Up @@ -181,7 +181,7 @@ def prepare_queue
end

# the main worker loop, executed by every worker process. It polls for messages
# from +Workers::Queue+ indefinitely, using +Workers::Processor+ to process
# from +Concierge::Queue+ indefinitely, using +Workers::Processor+ to process
# each of them.
#
# For each incoming message, it sets this process as +busy+ so that if any
Expand Down Expand Up @@ -262,7 +262,7 @@ def setup_database
def queue
@queue ||= begin
credentials = Concierge::Credentials.for("sqs")
Workers::Queue.new(credentials)
Concierge::Queue.new(credentials)
end
end

Expand Down
Loading

0 comments on commit ed2720d

Please sign in to comment.