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

statuses and max run for pending relationships #972

Merged
merged 5 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 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
laritakr marked this conversation as resolved.
Show resolved Hide resolved
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
Loading