-
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.
- Loading branch information
1 parent
9bdc15c
commit e11b388
Showing
23 changed files
with
312 additions
and
275 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,41 @@ | ||
# :nocov: | ||
class ApplicationJob < ActiveJob::Base | ||
# Automatically retry jobs that encountered a deadlock | ||
# retry_on ActiveRecord::Deadlocked | ||
class ApplicationJob < Que::Job | ||
class DuplicateJobError < StandardError | ||
end | ||
|
||
# Most jobs are safe to ignore if the underlying records are no longer available | ||
# discard_on ActiveJob::DeserializationError | ||
# @return [void] | ||
# We are checking for duplicate jobs to prevent undesirable mulitple actions in the event of blocked or slow jobs | ||
def run(*_args) | ||
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 | ||
|
||
# @return [void] | ||
def handle_error(error) | ||
message = "#{self.class.name} failed with '#{error.message}'" | ||
log(message) | ||
Sentry.capture_message(message, level: :error) if Rails.application.live? | ||
end | ||
|
||
# @return [String] | ||
def log(message) | ||
if ENV['RAILS_LOG_TO_STDOUT'].present? | ||
Rails.logger.info(message) | ||
else | ||
puts message | ||
end | ||
end | ||
end | ||
# :nocov: |
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 |
---|---|---|
@@ -1,5 +1,15 @@ | ||
class CompleteRegistrationMailJob < ScheduledJob | ||
class CompleteRegistrationMailJob < ApplicationJob | ||
# @return [void] | ||
def run | ||
NudgeMail.new.complete_registration | ||
super do | ||
notify_users | ||
end | ||
end | ||
|
||
private | ||
|
||
# @return [void] | ||
def notify_users | ||
User.complete_registration_recipients.each { |recipient| NotifyMailer.complete_registration(recipient) } | ||
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 |
---|---|---|
@@ -1,5 +1,18 @@ | ||
class ContinueTrainingMailJob < ScheduledJob | ||
class ContinueTrainingMailJob < ApplicationJob | ||
# @return [void] | ||
def run | ||
NudgeMail.new.continue_training | ||
super do | ||
notify_users | ||
end | ||
end | ||
|
||
private | ||
|
||
# @return [void] | ||
def notify_users | ||
User.continue_training_recipients.each do |recipient| | ||
progress = recipient.course | ||
NotifyMailer.continue_training(recipient, progress.current_modules.first) | ||
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 |
---|---|---|
@@ -1,28 +1,37 @@ | ||
class NewModuleMailJob < ScheduledJob | ||
def run | ||
return if new_module.nil? | ||
class NewModuleMailJob < ApplicationJob | ||
# @param release_id [Integer] | ||
# @return [void] | ||
def run(release_id) | ||
super do | ||
return if new_module.nil? | ||
|
||
notify_users(new_module) | ||
create_published_record(new_module) | ||
notify_users(new_module) | ||
create_published_record(new_module, Release.find(release_id)) | ||
end | ||
end | ||
|
||
private | ||
|
||
def create_published_record(mod) | ||
PreviouslyPublishedModule.create!(module_position: mod.position, name: mod.name, first_published_at: mod.published_at) | ||
# @param mod [Training::Module] | ||
# @param release [Release] | ||
# @return [ModuleRelease] | ||
def create_published_record(mod, release) | ||
ModuleRelease.create!(release_id: release.id, module_position: mod.position, name: mod.name, first_published_at: release.time) | ||
end | ||
|
||
# @param mod [Training::Module] | ||
# @return [void] | ||
def notify_users(mod) | ||
mail_service = NudgeMail.new | ||
mail_service.new_module(mod) | ||
User.completed_available_modules.each { |recipient| NotifyMailer.new_module(recipient, mod) } | ||
end | ||
|
||
# @return [Training::Module, nil] | ||
def new_module | ||
latest_published = Training::Module.ordered.reject(&:draft?).last | ||
if latest_published.position == PreviouslyPublishedModule.ordered.last.module_position | ||
if latest_published.position == ModuleRelease.ordered.last.module_position | ||
nil | ||
else | ||
Training::Module.ordered.reject(&:draft?).last | ||
latest_published | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,5 +1,15 @@ | ||
class StartTrainingMailJob < ScheduledJob | ||
class StartTrainingMailJob < ApplicationJob | ||
# @return [void] | ||
def run | ||
NudgeMail.new.start_training | ||
super do | ||
notify_users | ||
end | ||
end | ||
|
||
private | ||
|
||
# @return [void] | ||
def notify_users | ||
User.start_training_recipients.each { |recipient| NotifyMailer.start_training(recipient) } | ||
end | ||
end |
6 changes: 4 additions & 2 deletions
6
app/models/previously_published_module.rb → app/models/module_release.rb
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 was deleted.
Oops, something went wrong.
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 CreateModuleReleases < ActiveRecord::Migration[7.0] | ||
def change | ||
create_table :module_releases do |t| | ||
t.references :release, null: false, foreign_key: true | ||
t.integer :module_position, null: false | ||
t.string :name, null: false | ||
t.datetime :first_published_at, null: false | ||
t.timestamps | ||
end | ||
add_index :module_releases, :name, unique: true | ||
add_index :module_releases, :module_position, unique: true | ||
end | ||
end |
12 changes: 0 additions & 12 deletions
12
db/migrate/20230727102149_create_previously_published_modules.rb
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.