Skip to content

Commit

Permalink
assemble marc files
Browse files Browse the repository at this point in the history
  • Loading branch information
gkostin1966 committed Jun 10, 2019
1 parent 10b1281 commit 7d61780
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 32 deletions.
15 changes: 15 additions & 0 deletions app/programs/assemble_marc_files.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

module AssembleMarcFiles
class << self
def run
program = AssembleMarcFiles.new
program.execute
rescue StandardError => e
text = <<~MSG
AssembleMarcFiles run error (#{e})
MSG
NotifierMailer.administrators(text).deliver_now
end
end
end
47 changes: 47 additions & 0 deletions app/programs/assemble_marc_files/assemble_marc_files.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# frozen_string_literal: true

module AssembleMarcFiles
class AssembleMarcFiles
def execute
puts "hello"
end

# def run
# umpebc_products_modified.each do |modified_product|
# generate_product_marc_files(modified_product)
# end
# rescue StandardError => e
# text = <<~MSG
# AssembleMarcFiles run error (#{e})
# MSG
# NotifierMailer.administrators(text).deliver_now
# end
#
# private
#
# def generate_product_marc_files(product)
# product.dois.each do |doi|
# end
# end
#
# def umpebc_products_modified
# umpebc_product_family.products.map { |product| product if product.modified? }.compact
# end
#
# def umpebc_product_family
# @umpebc_product_family ||= begin
# product_families = LibPtgBox::LibPtgBox.new.product_families
# umpebc_family = nil
# product_families.each do |family|
# next unless /umpebc/i.match?(family.name)
#
# umpebc_family = family
# break
# end
# raise 'umpebc product family not found' unless umpebc_family
#
# umpebc_family
# end
# end
end
end
31 changes: 0 additions & 31 deletions app/runners/assemble_marc_files.rb

This file was deleted.

3 changes: 2 additions & 1 deletion config/initializers/scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
# Daily - do something every day
# (see "man 5 crontab" in your terminal)
scheduler.cron '0 0 * * *' do
NotifierMailer.administrators("Daily").deliver_now
Rails.logger.info "Daily #{Time.now}"
Rails.logger.flush
NotifierMailer.administrators("Daily").deliver_now
AssembleMarcFiles.run
end
File renamed without changes.
35 changes: 35 additions & 0 deletions spec/programs/assemble_marc_files_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe AssembleMarcFiles do
describe '#run' do
let(:program) { instance_double(AssembleMarcFiles::AssembleMarcFiles, "AssembleMarcFiles") }

before { allow(AssembleMarcFiles::AssembleMarcFiles).to receive(:new).and_return(program) }

context 'when execute program' do
before { allow(program).to receive(:execute) }

it 'program execute' do
described_class.run
expect(program).to have_received(:execute)
end
end

context 'when standard error' do
let(:mail) { double("NotifierMailer") } # rubocop:disable RSpec/VerifiedDoubles

before do
allow(program).to receive(:execute).and_raise(StandardError)
allow(NotifierMailer).to receive(:administrators).with("AssembleMarcFiles run error (StandardError)\n").and_return(mail)
allow(mail).to receive(:deliver_now)
end

it 'notifies administrators' do
described_class.run
expect(mail).to have_received(:deliver_now)
end
end
end
end

0 comments on commit 7d61780

Please sign in to comment.