Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 4 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ jobs:
- run:
name: Update Debian Packages
command: |
echo "deb http://http.debian.net/debian jessie-backports main" | sudo tee -a /etc/apt/sources.list
echo "deb http://archive.debian.org/debian/ jessie-backports main" | sudo tee -a /etc/apt/sources.list
echo "deb-src http://archive.debian.org/debian/ jessie-backports main" | sudo tee -a /etc/apt/sources.list
echo "Acquire::Check-Valid-Until false;" | sudo tee -a /etc/apt/apt.conf.d/10-nocheckvalid
echo 'Package: *\nPin: origin "archive.debian.org"\nPin-Priority: 500' | sudo tee -a /etc/apt/preferences.d/10-archive-pin
sudo apt-get update -qq
sudo apt-get upgrade -qq
sudo apt-get install -y -f software-properties-common build-essential default-libmysqlclient-dev mysql-client nodejs make apt-utils
Expand Down
40 changes: 40 additions & 0 deletions app/jobs/resend_email_article_recruit_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# frozen_string_literal: true

##
# Job for re-sending article recruit email
class ResendEmailArticleRecruitJob < ApplicationJob
# Defaults to 0
# job_options retry: 0

def perform(publication:, current_user: nil, previous_event: nil)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/AbcSize: Assignment Branch Condition size for perform is too high. [34.32/15]
Metrics/CyclomaticComplexity: Cyclomatic complexity for perform is too high. [9/6]
Metrics/MethodLength: Method has too many lines. [26/10]
Metrics/PerceivedComplexity: Perceived complexity for perform is too high. [9/7]

system_email = ENV['ED2_EMAIL_FROM']
event = previous_event || Event.create(Event::RESEND_EMAIL_ARTICLE_RECRUIT.merge(restartable: false, status: Event::STARTED[:name]))

event.update(
publication: publication,
message: "Initiated by #{current_user ? current_user[:email] : system_email }",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/SpaceInsideStringInterpolation: Space inside string interpolation detected.

restartable: false,
status: Event::STARTED[:name]
)

current_user.events << event if current_user

emails = [system_email.split(',')].flatten
emails << current_user[:email] if current_user
emails << publication.author_publications.map(&:email) if Rails.env.production?
emails.each do |email|
logger.debug "ResendEmailArticleRecruitJob.perform: Emailing recruitment email to #{email}"
ArticleRecruitMailer.with(email: email, publication: publication).resend_recruit_email.deliver_now
end
event.completed(
message: "Resend Article author recruitment email completed by #{current_user ? current_user[:email] : system_email} at #{Time.now}",
restartable: false,
status: Event::EMAIL[:name]
)
publication.await_claim!
rescue => e

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/RescueStandardError: Avoid rescuing without specifying an error class.

msg = 'EmailArticleRecruitJob.perform'
NotificationManager.log_exception(logger, msg, e)
event.error(restartable: true, message: "#{msg} : #{e.message}") if event

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/SafeNavigation: Use safe navigation (&.) instead of checking if an object exists before calling the method.

end
end
6 changes: 6 additions & 0 deletions app/mailers/article_recruit_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@ def recruit_email
@author_publication = @publication.author_publications.where(email: @email).first
mail(to: @email, subject: "Oregon State University Library invites you to deposit your recent publication: #{@publication.web_of_science_source_record[:uid]}")
end

def resend_recruit_email
@publication = params[:publication]
@author_publication = @publication.author_publications.where(email: @email).first
mail(to: @email, subject: "REMINDER: Oregon State University Library invites you to deposit your recent publication: #{@publication.web_of_science_source_record[:uid]}")
end
end
7 changes: 6 additions & 1 deletion app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class Event < ActiveRecord::Base
email_published_work: EmailPublishedWorkJob.to_s,
fetch_authors_directory_api: FetchAuthorsDirectoryApiJob.to_s,
fetch_wos_content: FetchWosContentJob.to_s,
email_article_recruit: EmailArticleRecruitJob.to_s
email_article_recruit: EmailArticleRecruitJob.to_s,
resend_email_article_recruit: ResendEmailArticleRecruitJob.to_s
}

# Statuses
Expand Down Expand Up @@ -53,6 +54,10 @@ class Event < ActiveRecord::Base
status: STARTED[:name],
restartable: true,
restartable_state: JSON.dump(method: RESTARTABLE_METHODS[:email_article_recruit]) }
RESEND_EMAIL_ARTICLE_RECRUIT = { name: 'Resend article recruit with email saved in AuthorPublication',
status: STARTED[:name],

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/AlignHash: Align the elements of a hash literal if they span more than one line.

restartable: true,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/AlignHash: Align the elements of a hash literal if they span more than one line.

restartable_state: JSON.dump(method: RESTARTABLE_METHODS[:resend_email_article_recruit]) }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/AlignHash: Align the elements of a hash literal if they span more than one line.


def completed(options = nil)
save_record(options.merge(status: options[:status] || COMPLETED[:name]))
Expand Down
9 changes: 8 additions & 1 deletion app/models/publication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def add_author_emails(people)
state :initialized, initial: true
state :fetching_authors
state :recruiting_authors
state :resending_recruiting_authors
state :awaiting_claim
state :awaiting_attachments
state :publication_exists
Expand All @@ -99,8 +100,14 @@ def add_author_emails(people)
end
transitions from: :fetching_authors, to: :recruiting_authors, guard: :completed_fetching_authors?
end
event :resend_recruit_authors do
after do
ResendEmailArticleRecruitJob.perform_later(publication: self)
end
transitions from: :await_claim, to: :resending_recruiting_authors
end
event :await_claim do
transitions from: :recruiting_authors, to: :awaiting_claim
transitions from: [:recruiting_authors, :resending_recruiting_authors], to: :awaiting_claim

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/SymbolArray: Use %i or %I for an array of symbols.

end
event :await_attachments do
transitions from: :awaiting_claim, to: :awaiting_attachments
Expand Down
14 changes: 14 additions & 0 deletions lib/tasks/resend_article_recruit_email.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

namespace :resend_article_recruit_email do
desc 'Re-send article recruit email for publications without attachment'
task resendarticlerecruitemail: :environment do
Publication.all.each do |pub|
# Find publications without attachment
if pub.publication_files.empty?
# Call re-send article recruit email
ResendEmailArticleRecruitJob.perform_later(pub)
end
end
end
end

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/TrailingBlankLines: Final newline missing.