-
Notifications
You must be signed in to change notification settings - Fork 0
[Draft] Re send article recruit email #228
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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) | ||
| 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 }", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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], | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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]) } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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])) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
| 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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Layout/TrailingBlankLines: Final newline missing. |
||
There was a problem hiding this comment.
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]