Class: Importo::ImportJobCallback
- Inherits:
-
ActiveJob::Base
- Object
- ActiveJob::Base
- Importo::ImportJobCallback
- Includes:
- Sidekiq::Batch::Callback
- Defined in:
- app/importers/importo/import_job_callback.rb
Instance Method Summary collapse
- #complete_import(import) ⇒ Object
-
#on_complete(status, options) ⇒ Object
(also: #on_success)
This is for sidekiq.
-
#perform(batch, context) ⇒ Object
This is for good_job.
Instance Method Details
#complete_import(import) ⇒ Object
12 13 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/importers/importo/import_job_callback.rb', line 12 def complete_import(import) return if import.blank? # Sidekiq's batch :complete event can fire as soon as every row has been # attempted once, even though some rows failed and are still awaiting a # retry. Bail out here so we don't finalize (and report a wrong count) # before every row has actually finished processing. return unless import.results.count == import.importer.send(:row_count) results_file = import.importer.results_file results_file = results_file.is_a?(StringIO) ? results_file : File.open(results_file) import.result.attach(io: results_file, filename: import.importer.file_name("results"), content_type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") ActiveRecord::Base.uncached do import. = I18n.t("importo.importers.result_message", nr: import.results.where("details @> ?", {state: "success"}.to_json).count, of: import.importer.send(:row_count)) end if import.can_complete? import.complete! else import.save! end end |
#on_complete(status, options) ⇒ Object Also known as: on_success
This is for sidekiq
40 41 42 43 44 |
# File 'app/importers/importo/import_job_callback.rb', line 40 def on_complete(status, ) = .deep_stringify_keys import = Import.find(["import_id"]) complete_import(import) end |
#perform(batch, context) ⇒ Object
This is for good_job
7 8 9 10 |
# File 'app/importers/importo/import_job_callback.rb', line 7 def perform(batch, context) import = Import.find(batch.properties[:import_id]) complete_import(import) end |