Skip to content

Commit

Permalink
Rubocop and codeclimate
Browse files Browse the repository at this point in the history
  • Loading branch information
richardmatthewsdev committed Aug 30, 2024
1 parent 7b7fa2e commit f8b2b6c
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 27 deletions.
26 changes: 10 additions & 16 deletions app/controllers/pipelines_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,23 @@
class PipelinesController < ApplicationController
include LastEditedBy

VALID_STATUSES = %w[queued running errored]

before_action :find_pipeline, only: %w[destroy clone]
before_action :assign_show_pipeline, only: %w[show update]
before_action :assign_show_variables, only: %w[show update]
before_action :assign_destinations, only: %w[show update]

def index
@pipeline = Pipeline.new

if params['status'].nil? || VALID_STATUSES.exclude?(params['status'])
@pipelines = pipelines
elsif params['status'] == 'queued'
@pipelines = PipelineJob.where.missing(:harvest_reports).map(&:pipeline).uniq
else
@pipelines = HarvestReport
.completed
.invert_where
.order(created_at: :desc)
.select { |report| report.status == params['status'] }
.map { |report| report.pipeline_job.pipeline }
.uniq
end
status = params['status']

@pipelines = if status == 'queued'
PipelineJob.where.missing(:harvest_reports).map(&:pipeline).uniq
elsif status == 'running'
HarvestReport.running.map { |report| report.pipeline_job.pipeline }
.uniq
else
pipelines
end
end

def show; end
Expand Down
20 changes: 14 additions & 6 deletions app/models/harvest_report.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
# frozen_string_literal: true

class HarvestReport < ApplicationRecord

scope :completed, -> { where(extraction_status: 'completed', transformation_status: 'completed', load_status: 'completed', delete_status: 'completed') }
scope :completed, lambda {
where(extraction_status: 'completed', transformation_status: 'completed',
load_status: 'completed', delete_status: 'completed')
}

belongs_to :pipeline_job, optional: true
belongs_to :harvest_job, optional: true

def self.active
HarvestReport.completed.invert_where.order(created_at: :desc)
end

def self.running
active.select { |report| report.status == 'running' }
end

STATUSES = %w[queued cancelled running completed errored].freeze

enum :extraction_status, STATUSES, prefix: :extraction
Expand All @@ -21,8 +31,7 @@ class HarvestReport < ApplicationRecord
enum :kind, { harvest: 0, enrichment: 1 }

METRICS = %w[
pages_extracted records_transformed
records_loaded records_rejected
pages_extracted records_transformed records_loaded records_rejected
records_deleted transformation_workers_queued
transformation_workers_completed load_workers_queued
load_workers_completed delete_workers_queued
Expand All @@ -34,8 +43,7 @@ class HarvestReport < ApplicationRecord
extraction_end_time transformation_start_time
transformation_updated_time transformation_end_time
load_start_time load_updated_time
load_end_time delete_start_time
delete_updated_time delete_end_time
load_end_time delete_start_time delete_updated_time delete_end_time
].freeze

def completed?
Expand Down
5 changes: 0 additions & 5 deletions app/views/pipelines/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@
<%= link_to 'Running', pipelines_path(status: 'running'),
class: "nav-link #{'active' if params['status'] == 'running'}" %>
</li>

<li class='nav-item'>
<%= link_to 'Errored', pipelines_path(status: 'errored'),
class: "nav-link #{'active' if params['status'] == 'errored'}" %>
</li>
</ul>
<% end %>

Expand Down
46 changes: 46 additions & 0 deletions spec/models/harvest_report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,52 @@
end
end

describe '#active' do
let!(:queued) do
create(:harvest_report, pipeline_job:, harvest_job:, extraction_status: 'queued', transformation_status: 'queued',
load_status: 'queued', delete_status: 'queued')
end
let!(:running_one) do
create(:harvest_report, pipeline_job:, harvest_job:, extraction_status: 'running', transformation_status: 'queued',
load_status: 'queued', delete_status: 'queued')
end
let!(:running_two) do
create(:harvest_report, pipeline_job:, harvest_job:, extraction_status: 'completed', transformation_status: 'queued',
load_status: 'queued', delete_status: 'queued')
end
let!(:completed) do
create(:harvest_report, pipeline_job:, harvest_job:, extraction_status: 'completed',
transformation_status: 'completed', load_status: 'completed', delete_status: 'completed')
end

it 'returns reports that are not completed' do
expect(HarvestReport.active.count).to eq 3
end
end

describe '#running' do
let!(:queued) do
create(:harvest_report, pipeline_job:, harvest_job:, extraction_status: 'queued', transformation_status: 'queued',
load_status: 'queued', delete_status: 'queued')
end
let!(:running_one) do
create(:harvest_report, pipeline_job:, harvest_job:, extraction_status: 'running', transformation_status: 'queued',
load_status: 'queued', delete_status: 'queued')
end
let!(:running_two) do
create(:harvest_report, pipeline_job:, harvest_job:, extraction_status: 'completed', transformation_status: 'queued',
load_status: 'queued', delete_status: 'queued')
end
let!(:completed) do
create(:harvest_report, pipeline_job:, harvest_job:, extraction_status: 'completed',
transformation_status: 'completed', load_status: 'completed', delete_status: 'completed')
end

it 'returns running reports' do
expect(HarvestReport.running.count).to eq(2)
end
end

describe '#completed' do
let!(:queued) do
create(:harvest_report, pipeline_job:, harvest_job:, extraction_status: 'queued', transformation_status: 'queued',
Expand Down

0 comments on commit f8b2b6c

Please sign in to comment.