Class: HouzzInventoryUpdaterWorker
- Inherits:
-
Object
- Object
- HouzzInventoryUpdaterWorker
- Includes:
- Sidekiq::Job
- Defined in:
- app/workers/houzz_inventory_updater_worker.rb
Overview
Sidekiq worker: houzz inventory updater.
Class Method Summary collapse
-
.lock_args(args) ⇒ Object
First two keys are sufficient to determine this job as unique.
Instance Method Summary collapse
- #instantiate_transporter(transporter, transporter_profile = nil) ⇒ Object
- #perform(ecl_id, count, total, inventory_entry_json, transporter, transporter_profile, remote_path, transporter_send_method) ⇒ Object
Class Method Details
.lock_args(args) ⇒ Object
First two keys are sufficient to determine this job as unique
10 11 12 |
# File 'app/workers/houzz_inventory_updater_worker.rb', line 10 def self.lock_args(args) [args[0], args[1]] end |
Instance Method Details
#instantiate_transporter(transporter, transporter_profile = nil) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'app/workers/houzz_inventory_updater_worker.rb', line 39 def instantiate_transporter(transporter, transporter_profile = nil) case transporter when :sftp 'Transport::SftpConnection'.constantize.new(transporter_profile) when :http_api Transport::HttpApiConnection.new({ profile: transporter_profile }) else raise "Unknown transporter: #{transporter}" end end |
#perform(ecl_id, count, total, inventory_entry_json, transporter, transporter_profile, remote_path, transporter_send_method) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/workers/houzz_inventory_updater_worker.rb', line 14 def perform(ecl_id, count, total, inventory_entry_json, transporter, transporter_profile, remote_path, transporter_send_method) ecl = EdiCommunicationLog.find(ecl_id) return unless ecl&.processing? transport = instantiate_transporter(transporter.to_sym, transporter_profile.to_sym) res = transport.send_data(inventory_entry_json, remote_path, transporter_send_method) logger.info "Sending inventory update for entry: #{count} of #{total} #{inventory_entry_json}, using #{transporter_send_method} #{remote_path}, res: #{res}" ecl.transmit_datetime = Time.current ecl.notes = ecl.notes.to_s + "| entry: #{count} of #{total}: HTTP CODE: #{res[:http_result].try(:status)}, HTTP BODY: #{res[:http_result].try(:body)}, " ecl.save if res[:success] if count == total # here we assume that if we got to the last one we can mark it complete if all good if ecl.notes.index('| error').nil? ecl.complete! else ecl.error! end end else # add an error and show its payload but keep going until the end ecl.notes = ecl.notes.to_s + "| error payload: #{inventory_entry_json}" ecl.save end end |