-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* wip: add complete registration reminder email * wip: update spec * add start training email notification * add training emails condition to email recipients * update recipient selector spec and user scope * rubocop * wip: add nudge email for new module * wip: new module alert email * add nudge emails for new module * update recipient selector and spec * fix syntax error * remove new module nudge email * refactor nudge mails * update dashboard spec update time * refactor nudge mails * wip: new module nudge email * add new module release nudge emails * add sandbox contentful env * revert changes to app_config * check new modules for duplicate names for contentful sandbox * add email send to test release webhook * add new modules check to change method in hook controller * remove new modules check on change method * add new modules check to change method in hook controller * remove unnecessary mail jobs from hook controller * check new modules for repeated names for sandbox * update spec and remove package-lock.json * rubocop and revert yarn.lock changes * revert schema changes * use cms training modules * use course progress service for continue module nudge emails * make modules_in_progress a method on user model * update interval time on spec * fix typo * rubocop * rubocop * use user course method for modules progress * revert dashboard interval change * use que-locks to prevent duplicate concurrent mailjobs * add que-locks gem * revert change to que version * change que version * protect against duplicate mail jobs in queue * rubocop * add comment to training module record migration * add yard annotation * add job helper to guard against duplicate queued jobs * refactor nudge mail service and spec * refactor new module check * wip: create base job to guard against duplicate jobs * refactor spec * refactor scheduled que jobs * update email preferences logic on account page * refactor nudge mail jobs * change contentful env to sandbox * add changes to make testing easier * rubocop * fix merge conflicts * fix merge conflicts * make completed method public in course progress * fix bug for user account page * remove typo from course progress * change new module mail job from run to enqueue for testing * in the event of no modulerelease records, populate with training module data * rubocop * change contentful env to test * remove draft new module check for testing * remove duplicate check for testing * update timestamps * trigger new module email even if no released module records for testing * rubocop * rubocop * update spec for testing * comment out new module mail spec for testing * comment out new module mail spec for testing * skip new module spec for testing * comment out new module mail spec for testing * add draft check back to new module job * rubocop * rubocop * send email to more users for testing and add sentry output * send latest module in new mod mailer to all users for testing * rubocop * add filtered recipients back * add filtered recipients back * select first module for nudge email * remove create new module release record, for testing * send mail to all users * send new module email to all users when there is a release * rubocop * trigger email taken mail when release for testing notify * remove commented test code * remove application job super to simplify testing * ruboocop * log to sentry when job runs * return recipients to contentful response for debugging * more sentry logging * send email directly in release hook * more sentry logging * call notify properly * fix email sending for nudge mail jobs * update base job and spec * rubocop * update mail job specs * add check for empty ModuleRelease table * rubocop * update for qa * fix merge conflicts * fix merge conflicts * scenario 2 qa * scenario 3 qa * fix typo * update continuetraining mail job * fix typo in notify mailer * add live scope to modules for email job * fix continue training mail job * revert changes made for qa testing * refactor mail jobs * use with progress context in mail specs * add nudge mail recipients to user overview data export * remove unused matcher * add mail job shared context * Rework mail prompt shared context to assert without using log output and that specific users are messaged * refactor: use dynamic user scope to select recipients base mail job * fix user overview data model to reference correct recipients scopes * remove unused error from mail job * rubocop * remove rogue comments * remove completed todo * remove missed comments * add comments to document mail job spec setup * remove missed comment * rubocop --------- Co-authored-by: Peter Hamilton <[email protected]>
- Loading branch information
1 parent
4872f3b
commit 1b1109e
Showing
33 changed files
with
539 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
class ApplicationJob < Que::Job | ||
class DuplicateJobError < StandardError | ||
end | ||
|
||
# We are checking for duplicate jobs to prevent undesirable mulitple actions in the event of blocked or slow jobs | ||
# | ||
# @return [void] | ||
def run(*) | ||
start_time = Time.zone.now | ||
log "#{self.class.name} running" | ||
|
||
if duplicate_job_queued? | ||
raise DuplicateJobError, "#{self.class.name} already queued" | ||
elsif block_given? | ||
yield | ||
end | ||
|
||
log "#{self.class.name} finished in #{(Time.zone.now - start_time).round(2)} seconds" | ||
end | ||
|
||
private | ||
|
||
# @return [Boolean] | ||
def duplicate_job_queued? | ||
Que.job_stats.any? { |job| job[:job_class] == self.class.name && job[:count] > 1 } | ||
end | ||
|
||
# @param error [Error] | ||
# @return [void] | ||
def handle_error(error) | ||
log("#{self.class.name} failed with '#{error.message}'") | ||
end | ||
|
||
# @return [String] | ||
def log(message) | ||
Sentry.capture_message(message, level: :info) if Rails.application.live? | ||
|
||
if ENV['RAILS_LOG_TO_STDOUT'].present? | ||
Rails.logger.info(message) | ||
elsif ENV['VERBOSE'].present? | ||
puts message | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class CompleteRegistrationMailJob < MailJob | ||
def run | ||
super do | ||
self.class.recipients.each(&:send_complete_registration_notification) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class ContinueTrainingMailJob < MailJob | ||
def run | ||
super do | ||
self.class.recipients.each do |recipient| | ||
recipient.modules_in_progress.each do |mod_name| | ||
mod = Training::Module.by_name(mod_name) | ||
recipient.send_continue_training_notification(mod) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class MailJob < ApplicationJob | ||
# @return [Array<User>] | ||
def self.recipients | ||
scope_name = "#{name.underscore}_recipients" | ||
User.send(scope_name) | ||
end | ||
|
||
def run(*) | ||
super | ||
|
||
log("#{self.class.name}: #{self.class.recipients.count} recipients") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
class NewModuleMailJob < MailJob | ||
# @param release_id [Integer] | ||
def run(release_id) | ||
super do | ||
return unless new_module_published? | ||
|
||
self.class.recipients.each do |recipient| | ||
recipient.send_new_module_notification(latest_module) | ||
end | ||
|
||
newest_release = Release.find(release_id) | ||
|
||
record_module_release(latest_module, newest_release) | ||
end | ||
end | ||
|
||
private | ||
|
||
# @return [Training::Module] | ||
def latest_module | ||
Training::Module.live.last | ||
end | ||
|
||
# @return [Boolean] | ||
def new_module_published? | ||
return false unless ModuleRelease.exists? | ||
|
||
ModuleRelease.ordered.last.module_position < latest_module.position | ||
end | ||
|
||
# @param mod [Training::Module] | ||
# @param release [Release] | ||
# @return [ModuleRelease] | ||
def record_module_release(mod, release) | ||
ModuleRelease.create!( | ||
release_id: release.id, | ||
module_position: mod.position, | ||
name: mod.name, | ||
first_published_at: release.time, | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class StartTrainingMailJob < MailJob | ||
def run | ||
super do | ||
self.class.recipients.each(&:send_start_training_notification) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.