Skip to content

Commit

Permalink
statuses and max run for pending relationships
Browse files Browse the repository at this point in the history
  • Loading branch information
orangewolf committed Aug 23, 2024
1 parent ec8be99 commit 322dc7a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
7 changes: 4 additions & 3 deletions app/jobs/bulkrax/create_relationships_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class CreateRelationshipsJob < ApplicationJob
# is the child in the relationship, and vice versa if a child_identifier is passed.
#
# rubocop:disable Metrics/MethodLength
def perform(parent_identifier:, importer_run_id: nil, run_user: nil) # rubocop:disable Metrics/AbcSize
def perform(parent_identifier:, importer_run_id: nil, run_user: nil, failure_count: 0) # rubocop:disable Metrics/AbcSize
importer_run = Bulkrax::ImporterRun.find(importer_run_id) if importer_run_id
user = run_user || importer_run&.user
ability = Ability.new(user)
Expand All @@ -78,6 +78,7 @@ def perform(parent_identifier:, importer_run_id: nil, run_user: nil) # rubocop:d
@parent_record_members_added = true
rescue => e
number_of_failures += 1
rel.set_status_info(e, importer_run)
errors << e
end
end
Expand Down Expand Up @@ -107,9 +108,9 @@ def perform(parent_identifier:, importer_run_id: nil, run_user: nil) # rubocop:d
# rubocop:enable Rails/SkipsModelValidations

parent_entry&.set_status_info(errors.last, importer_run)

failure_count += 1
# TODO: This can create an infinite job cycle, consider a time to live tracker.
reschedule(parent_identifier: parent_identifier, importer_run_id: importer_run_id)
reschedule(parent_identifier: parent_identifier, importer_run_id: importer_run_id, failure_count: failure_count) if failure_count < 5
return errors # stop current job from continuing to run after rescheduling
else
# rubocop:disable Rails/SkipsModelValidations
Expand Down
2 changes: 2 additions & 0 deletions app/models/bulkrax/pending_relationship.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

module Bulkrax
class PendingRelationship < ApplicationRecord
include Bulkrax::StatusInfo

belongs_to :importer_run

# Ideally we wouldn't have a column named "order", as it is a reserved SQL term. However, if we
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddErrorTrackingToPendingRelationships < ActiveRecord::Migration[6.1]
def change
add_column :bulkrax_pending_relationships, :status_message, :string, default: 'Pending' unless column_exists?(:bulkrax_pending_relationships, :status_message)
end
end

0 comments on commit 322dc7a

Please sign in to comment.