Class: SpreeCmCommissioner::Exports::OperatorGuestJsonGzip
- Inherits:
-
SpreeCmCommissioner::Export
- Object
- Spree::Base
- Base
- SpreeCmCommissioner::Export
- SpreeCmCommissioner::Exports::OperatorGuestJsonGzip
- Defined in:
- app/models/spree_cm_commissioner/exports/operator_guest_json_gzip.rb
Constant Summary collapse
- BATCH_INCLUDES =
[ :occupation, :user, { check_ins: %i[check_in_by check_in_session], line_item: [:variant, { order: :bill_address }] } ].freeze
Instance Method Summary collapse
-
#export ⇒ Object
override.
Methods inherited from SpreeCmCommissioner::Export
#enqueue_export, #exported_file_name, #exported_file_url, #set_uuid
Instance Method Details
#export ⇒ Object
override
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/models/spree_cm_commissioner/exports/operator_guest_json_gzip.rb', line 16 def export self. = [] << "Export started at #{Time.current.iso8601}" update(status: :progress, track_messages: ) guests_query = SpreeCmCommissioner::GuestSearcherQuery.new(event_id: exportable_id).call self.guests_count = guests_query.count(:id) << "Processing #{guests_count} guests in batches" update(track_messages: , guests_count: guests_count) # We use 2 temp files to avoid loading everything into memory: # - File 1: guest1,guest2,guest3... (just the data array content) # - File 2: user1,order1,user2... (just the included array content) # Then we merge them into: {"data":[File1],"included":[File2]} guests_file = Tempfile.new(['guests', '.json']) included_file = Tempfile.new(['included', '.json']) output_gz_file = Tempfile.new(['export', '.json.gz']) begin total_processed = stream_export_data_and_includes_to_separate_files(guests_query, guests_file, included_file) self.guests_count = total_processed stream_export_merge_and_compress_data_and_includes_to_a_single_file(guests_file, included_file, output_gz_file) attach_file_to_record(output_gz_file) ensure cleanup_temp_files(guests_file, included_file, output_gz_file) end rescue StandardError => e CmAppLogger.error(label: "#{self.class.name}#export", data: { export_id: id, error: e., backtrace: e.backtrace }) track_errors = [] track_errors << "Error: #{e.} at #{Time.current.iso8601}" track_errors << e.backtrace.take(5).join("\n") if e.backtrace.present? update(status: :failed, track_errors: track_errors) end |