Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calendar synchronisation #125

Merged
merged 31 commits into from
Jul 14, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
f3f059e
Drop `update_calendar` and associated code.
Jul 8, 2016
6a4a0a4
Rename Workers::Synchronisation to Workers::PropertySynchronisation.
Jul 8, 2016
982a829
Introduce background workers, configurable per supplier.
Jul 11, 2016
4dd4ee3
Ability to filter workers for a given supplier.
Jul 11, 2016
61c05a8
Include flows for creating suppliers and associated workers.
Jul 11, 2016
afb4826
Drop the contradicting on_delete: set null option on foreign keys.
Jul 11, 2016
5438de3
Flexible supplier sync workers configuration via suppliers.yml.
Jul 11, 2016
74dff28
Drops `next_run_at` column from hosts.
Jul 11, 2016
76dd403
Rename supplier creation flow to host creation flow.
Jul 12, 2016
7393342
Ability to query for hosts by identifier and supplier.
Jul 12, 2016
cdbc667
Query for backround workers associated with a host instead of supplier.
Jul 12, 2016
85d8939
Create background workers associated with hosts.
Jul 12, 2016
e046e38
Revert suppliers rake task to simplicity.
Jul 12, 2016
e004485
Run host creation in a database transaction.
Jul 12, 2016
1e66a17
Include rake task to update workers definition for all hosts.
Jul 12, 2016
e04b467
Support querying for pending background workers.
Jul 12, 2016
12c3cae
Schedule workers rather than hosts.
Jul 12, 2016
df7a08b
Process background workers instead of sync operations.
Jul 12, 2016
f985e48
Background worker coordination by the queue processor.
Jul 12, 2016
a3a4294
Update AtLeisure event name according to recent changes.
Jul 12, 2016
5041bf7
Introduce Roomorama::Calendar to specify rates and availabilities.
Jul 12, 2016
45be50a
Add new UpdateCalendar Roomorama API operation.
Jul 12, 2016
9e39461
Include type of synchronisation worker when sync process starts.
Jul 12, 2016
5050890
Add stats and type to sync processes.
Jul 13, 2016
d7831ce
Migrate to stats field on property synchronisation.
Jul 13, 2016
0d1d969
Validate calendars when required.
Jul 13, 2016
d230af3
Operation runner for calendar updates.
Jul 13, 2016
bd1ff84
Introduce a CalendarSynchronisation helper class.
Jul 13, 2016
267b475
Permanently delete property counters from sync_processes.
Jul 13, 2016
9600f7b
Update change log.
Jul 13, 2016
cc681fb
Documentation fixes.
Jul 14, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Flexible supplier sync workers configuration via suppliers.yml.
  • Loading branch information
Renato Mascarenhas committed Jul 12, 2016
commit 5438de374dd1b228a9483376ee0e0f7c43b967c1
8 changes: 7 additions & 1 deletion config/suppliers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@
# Only suppliers for which the full integration flow is completed should be
# added here (properties synchronisation as well as webhooks.)

- AtLeisure
atleisure:
name: "AtLeisure"
workers:
metadata:
every: "1d"
availabilities:
every: "5h"
83 changes: 71 additions & 12 deletions lib/tasks/suppliers.rake
Original file line number Diff line number Diff line change
@@ -1,22 +1,81 @@
require "yaml"

namespace :suppliers do
desc "Loads the suppliers.yml file into the database"
task load: :environment do
path = Hanami.root.join("config", "suppliers.yml").to_s
names = YAML.load_file(path) || [] # if the file is empty, +load_file+ returns +false+
# +SupplierLoader+
#
# Wrapper class for +Concierge::Flows::SupplierCreation+ which parses the supplier
# declaration (usually on +config/suppliers.yml+) and creates the associated records.
#
# Wraps the whole operation in a database transaction and validates that all suppliers
# contain at least one +metadata+ worker.
class SupplierLoader
class InvalidConfigurationError < StandardError
def initialize(path, error)
super("Configuration file at #{path} is invalid: #{error}")
end
end

attr_reader :path, :content

def initialize(path)
@path = path
@content = YAML.load_file(path)
end

def load!
total = 0

names.map do |name|
existing = SupplierRepository.named(name)
transaction do
content.each do |supplier, definition|
workers_definition = {
metadata: {
every: get(definition, "workers.metadata.every")
}
}

if definition["workers"]["availabilities"]
workers_definition.merge!(
availabilities: {
every: get(definition, "workers.availabilities.every")
}
)
end

unless existing
supplier = Supplier.new(name: name)
SupplierRepository.create(supplier)
total += 1
result = Concierge::Flows::SupplierCreation.new(
name: supplier,
workers: workers_definition
).perform

unless result.success?
raise InvalidConfigurationError(path, "Failed to persist data: check configuration")
end
end

total += 1
end

puts "Done. #{total} suppliers created."
total
end

private

def get(hash, key)
Concierge::SafeAccessHash.new(hash.to_h).get(key) ||
(raise InvalidConfigurationError.new(path, "No key #{key} found"))
end

def transaction
SupplierRepository.transaction { yield }
end

end


namespace :suppliers do
desc "Loads the suppliers.yml file into the database"
task load: :environment do
path = Hanami.root.join("config", "suppliers.yml").to_s
total = SupplierLoader.new(path).load!

puts "Done. #{total} suppliers persisted."
end
end