Skip to content

Commit

Permalink
skip process with deactivated host
Browse files Browse the repository at this point in the history
  • Loading branch information
Traf333 committed Sep 12, 2016
1 parent 43d3b51 commit bb536dd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ how this file is formatted and how the process works.
## Unreleased
### Added
- fee percentage for hosts on Web app on suppliers#show.
- `Workers::Suppliers::Kigo::Legacy::Calendar` skip process for deactivated hosts

### Fixed
- Kigo property images with non-Latin characters
Expand Down
11 changes: 9 additions & 2 deletions apps/workers/suppliers/kigo/legacy/calendar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ def initialize(host, identifiers)
end

def perform
return if host_deactivated?(properties.first)

properties.each do |property|
id = property.identifier.to_i
synchronisation.start(id) do
Expand All @@ -33,19 +35,24 @@ def perform
private

def properties
PropertyRepository.from_host(host).identified_by(identifiers)
@properties ||= PropertyRepository.from_host(host).identified_by(identifiers)
end

def importer
@importer ||= Kigo::Importer.new(credentials, request_handler)
end

def request_handler
Kigo::LegacyRequest.new(credentials)
@request_handler ||= Kigo::LegacyRequest.new(credentials)
end

def credentials
Concierge::Credentials.for(Kigo::Legacy::SUPPLIER_NAME)
end

def host_deactivated?(property)
result = Kigo::HostCheck.new(property.identifier, request_handler).check
result.success? && result.value
end
end
end
6 changes: 6 additions & 0 deletions spec/workers/suppliers/kigo/legacy/calendar_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@
expect(stats[:unavailable_records]).to eq 0
end

it 'stops process with deactivated host' do
allow_any_instance_of(Kigo::HostCheck).to receive(:check) { Result.new(true) }

expect { subject.perform }.not_to change { SyncProcessRepository.count }
end

end

end

0 comments on commit bb536dd

Please sign in to comment.