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

🐛 Fix importers sorting for last run and next run #977

Merged
merged 5 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
7 changes: 4 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ jobs:
run: bundle exec rake spec

- name: Upload coverage results
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4.4.0
with:
name: coverage-report-${{ matrix.ruby }}
path: coverage
path: coverage/**
include-hidden-files: true

coverage:
runs-on: ubuntu-latest
Expand All @@ -56,7 +57,7 @@ jobs:

steps:
- name: Download coverage report
uses: actions/download-artifact@v2
uses: actions/download-artifact@v4.1.8
with:
name: coverage-report-2.7
path: coverage
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/bulkrax/datatables.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Blacklight.onLoad(function() {
{ "data": "name" },
{ "data": "status_message" },
{ "data": "created_at" },
{ "data": "download" },
{ "data": "download", "orderable": false },
{ "data": "actions", "orderable": false }
],
initComplete: function () {
Expand Down
25 changes: 25 additions & 0 deletions app/models/bulkrax/importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ class Importer < ApplicationRecord # rubocop:disable Metrics/ClassLength

delegate :create_parent_child_relationships, :valid_import?, :write_errored_entries_file, :visibility, to: :parser

after_save :set_last_imported_at_from_importer_run
after_save :set_next_import_at_from_importer_run

attr_accessor :only_updates, :file_style, :file
attr_writer :current_run

Expand Down Expand Up @@ -247,5 +250,27 @@ def path_string
rescue
"#{self.id}_#{self.created_at.strftime('%Y%m%d%H%M%S')}"
end

private

# Adding this here since we can update the importer without running the importer.
# When we simply save the importer (as in just updating the importer from the options),
# it does not trigger the after_save callback in the importer_run.
def set_last_imported_at_from_importer_run
return if @skip_set_last_imported_at # Prevent infinite loop

@skip_set_last_imported_at = true
importer_runs.last&.set_last_imported_at
@skip_set_last_imported_at = false
end

# @see #set_last_imported_at_from_importer_run
def set_next_import_at_from_importer_run
return if @skip_set_next_import_at # Prevent infinite loop

@skip_set_next_import_at = true
importer_runs.last&.set_next_import_at
@skip_set_next_import_at = false
end
end
end
11 changes: 11 additions & 0 deletions app/models/bulkrax/importer_run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ class ImporterRun < ApplicationRecord
has_many :statuses, as: :runnable, dependent: :destroy
has_many :pending_relationships, dependent: :destroy

after_save :set_last_imported_at
after_save :set_next_import_at

def parents
pending_relationships.pluck(:parent_id).uniq
end
Expand All @@ -15,5 +18,13 @@ def user
# fallback to the configured user.
importer.user || Bulkrax.fallback_user_for_importer_exporter_processing
end

def set_last_imported_at
importer.update(last_imported_at: importer.last_imported_at)
end

def set_next_import_at
importer.update(next_import_at: importer.next_import_at)
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddLastImportedAtToBulkraxImporters < ActiveRecord::Migration[5.1]
def change
add_column :bulkrax_importers, :last_imported_at, :datetime unless column_exists?(:bulkrax_importers, :last_imported_at)
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddNextImportAtToBulkraxImporters < ActiveRecord::Migration[5.1]
def change
add_column :bulkrax_importers, :next_import_at, :datetime unless column_exists?(:bulkrax_importers, :next_import_at)
end
end
Loading