diff --git a/app/models/harvest_job.rb b/app/models/harvest_job.rb
index 1f2d105c..6dc0758f 100644
--- a/app/models/harvest_job.rb
+++ b/app/models/harvest_job.rb
@@ -7,7 +7,7 @@ class HarvestJob < ApplicationRecord
belongs_to :pipeline_job
belongs_to :harvest_definition
belongs_to :extraction_job, optional: true
- has_one :harvest_report, dependent: :destroy
+ has_one :harvest_report, dependent: nil
delegate :extraction_definition, to: :harvest_definition
delegate :transformation_definition, to: :harvest_definition
diff --git a/app/models/harvest_report.rb b/app/models/harvest_report.rb
index 25c7f5c3..0c11b056 100644
--- a/app/models/harvest_report.rb
+++ b/app/models/harvest_report.rb
@@ -1,8 +1,8 @@
# frozen_string_literal: true
class HarvestReport < ApplicationRecord
- belongs_to :pipeline_job
- belongs_to :harvest_job
+ belongs_to :pipeline_job, optional: true
+ belongs_to :harvest_job, optional: true
STATUSES = %w[queued cancelled running completed errored].freeze
@@ -11,9 +11,9 @@ class HarvestReport < ApplicationRecord
enum :load_status, STATUSES, prefix: :load
enum :delete_status, STATUSES, prefix: :delete
- delegate :harvest_definition, to: :harvest_job
- delegate :extraction_definition, to: :harvest_job
- delegate :transformation_definition, to: :harvest_job
+ delegate :harvest_definition, to: :harvest_job, allow_nil: true
+ delegate :extraction_definition, to: :harvest_job, allow_nil: true
+ delegate :transformation_definition, to: :harvest_job, allow_nil: true
enum :kind, { harvest: 0, enrichment: 1 }
@@ -97,7 +97,7 @@ def ready_to_delete_previous_records?
private
def considered_cancelled?
- statuses.any?('cancelled') || harvest_job.cancelled? || pipeline_job.cancelled?
+ statuses.any?('cancelled') || harvest_job&.cancelled? || pipeline_job.cancelled?
end
def considered_running?
diff --git a/app/sidekiq/harvest_worker.rb b/app/sidekiq/harvest_worker.rb
index 0c93c44c..7c3235f4 100644
--- a/app/sidekiq/harvest_worker.rb
+++ b/app/sidekiq/harvest_worker.rb
@@ -6,7 +6,8 @@ def child_perform(harvest_job)
@pipeline_job = harvest_job.pipeline_job
@harvest_report = HarvestReport.create(pipeline_job: @pipeline_job, harvest_job: @harvest_job,
- kind: @harvest_job.harvest_definition.kind)
+ kind: @harvest_job.harvest_definition.kind,
+ definition_name: @harvest_job.harvest_definition.name)
if @pipeline_job.extraction_job.nil? || @harvest_job.harvest_definition.enrichment?
create_extraction_job
diff --git a/app/views/pipeline_jobs/index.html.erb b/app/views/pipeline_jobs/index.html.erb
index 2fb50990..3878a3d9 100644
--- a/app/views/pipeline_jobs/index.html.erb
+++ b/app/views/pipeline_jobs/index.html.erb
@@ -67,7 +67,7 @@
) %>
- <%= report.harvest_job.name %> |
+ <%= report.definition_name || report.harvest_job.name %> |
<% if pipeline_job.schedule.present? %>
Schedule
@@ -88,30 +88,32 @@
| <%= report.records_rejected %> |
<%= report.records_deleted %> |
-
-
+ <% end %>
|
<% else %>
diff --git a/db/migrate/20240725030305_add_definition_name_to_harvest_report.rb b/db/migrate/20240725030305_add_definition_name_to_harvest_report.rb
new file mode 100644
index 00000000..0561e835
--- /dev/null
+++ b/db/migrate/20240725030305_add_definition_name_to_harvest_report.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+class AddDefinitionNameToHarvestReport < ActiveRecord::Migration[7.1]
+ def change
+ add_column :harvest_reports, :definition_name, :string
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 2c981fe6..2ce42308 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema[7.0].define(version: 2024_05_06_215031) do
+ActiveRecord::Schema[7.1].define(version: 2024_07_25_030305) do
create_table "destinations", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.string "name", null: false
t.string "url", null: false
@@ -143,6 +143,7 @@
t.timestamp "transformation_updated_time"
t.timestamp "load_updated_time"
t.timestamp "delete_updated_time"
+ t.string "definition_name"
t.index ["harvest_job_id"], name: "index_harvest_reports_on_harvest_job_id"
t.index ["pipeline_job_id"], name: "index_harvest_reports_on_pipeline_job_id"
end
diff --git a/spec/models/extraction_definition_spec.rb b/spec/models/extraction_definition_spec.rb
index d83ba9f9..793b6219 100644
--- a/spec/models/extraction_definition_spec.rb
+++ b/spec/models/extraction_definition_spec.rb
@@ -204,8 +204,8 @@
expect { subject.destroy }.to change(HarvestJob, :count).by(-1)
end
- it "destroys the harvest reports" do
- expect { subject.destroy }.to change(HarvestReport, :count).by(-1)
+ it "does not destroy the harvest reports" do
+ expect { subject.destroy }.to change(HarvestReport, :count).by(0)
end
end
diff --git a/spec/models/harvest_definition_spec.rb b/spec/models/harvest_definition_spec.rb
index eabdb110..61d2d5af 100644
--- a/spec/models/harvest_definition_spec.rb
+++ b/spec/models/harvest_definition_spec.rb
@@ -155,7 +155,7 @@
context "when a harvest definition has previously been run" do
let!(:destination) { create(:destination) }
- let!(:pipeline_job) { create(:pipeline_job, pipeline: pipeline, destination:) }
+ let!(:pipeline_job) { create(:pipeline_job, pipeline: pipeline, destination:, harvest_definitions_to_run: [harvest_definition.id.to_s]) }
let!(:harvest_job) { create(:harvest_job, :completed, harvest_definition:, pipeline_job:) }
let!(:harvest_report) { create(:harvest_report, pipeline_job:, harvest_job:) }
@@ -167,8 +167,8 @@
expect { harvest_definition.destroy }.to change(HarvestJob, :count).by(-1)
end
- it "destroys the harvest reports" do
- expect { harvest_definition.destroy }.to change(HarvestReport, :count).by(-1)
+ it "does not destroy the harvest reports" do
+ expect { harvest_definition.destroy }.to change(HarvestReport, :count).by(0)
end
end
end
diff --git a/spec/models/harvest_report_spec.rb b/spec/models/harvest_report_spec.rb
index e25fd2dd..68df85f8 100644
--- a/spec/models/harvest_report_spec.rb
+++ b/spec/models/harvest_report_spec.rb
@@ -3,7 +3,7 @@
require 'rails_helper'
RSpec.describe HarvestReport do
- subject { create(:harvest_report, pipeline_job:, harvest_job:) }
+ subject { create(:harvest_report, pipeline_job:, harvest_job:, definition_name: harvest_job.harvest_definition.name) }
let(:pipeline) { create(:pipeline) }
let(:destination) { create(:destination) }
@@ -12,7 +12,13 @@
let(:harvest_job) { create(:harvest_job, harvest_definition:, pipeline_job:) }
describe 'associations' do
- it { is_expected.to belong_to(:pipeline_job) }
+ it { is_expected.to belong_to(:pipeline_job).optional }
+ end
+
+ describe '#initialize' do
+ it 'has the same name as its harvest definition' do
+ expect(subject.definition_name).to eq harvest_definition.name
+ end
end
describe 'status checks' do