-
Notifications
You must be signed in to change notification settings - Fork 6
Added whenever gem to update slug tags every day and sync user names with Accounts #359
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
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,16 @@ | ||
| class UpdateSlugs | ||
| lev_routine transaction: :no_transaction | ||
|
|
||
| protected | ||
|
|
||
| def exec | ||
| Exercise.preload(:publication).in_batches(of: 100, load: true) do |exercises| | ||
| Exercise.transaction do | ||
| updated_exercise_ids = exercises.select(:id).filter(&:set_slug_tags!).map(&:id) | ||
| next if updated_exercise_ids.empty? | ||
|
|
||
| Exercise.where(id: updated_exercise_ids).update_all updated_at: Time.current | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or 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,5 @@ | ||
| # Server time is UTC | ||
| # Times below are interpreted that way | ||
|
|
||
| every(1.minute) { rake 'cron:minute' } | ||
| every(1.day, at: '8 AM') { rake 'cron:day' } # Midnight-1AM Pacific/2-3AM Central/3-4AM Eastern |
This file contains hidden or 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 hidden or 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,10 @@ | ||
| namespace :cron do | ||
| task day: :log_to_stdout do | ||
| Rails.logger.debug 'Starting daily cron' | ||
|
|
||
| Rails.logger.info 'UpdateSlugs.call' | ||
| OpenStax::RescueFrom.this { UpdateSlugs.call } | ||
|
|
||
| Rails.logger.debug 'Finished daily cron' | ||
| end | ||
| end |
This file contains hidden or 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,10 @@ | ||
| namespace :cron do | ||
| task minute: :log_to_stdout do | ||
| Rails.logger.debug 'Starting minute cron' | ||
|
|
||
| Rails.logger.info 'rake openstax:accounts:sync:accounts' | ||
| OpenStax::RescueFrom.this { Rake::Task['openstax:accounts:sync:accounts'].invoke } | ||
|
|
||
| Rails.logger.debug 'Finished minute cron' | ||
| end | ||
| end | ||
This file contains hidden or 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,20 @@ | ||
| # http://jerryclinesmith.me/blog/2014/01/16/logging-from-rake-tasks/ | ||
| desc 'Include this task as another task\'s dependency to cause Rails.logger to also print to STDOUT' | ||
| task :log_to_stdout, [ :log_level ] => :environment do |tt, args| | ||
| # Do nothing in the test environment, since we don't want stdout there | ||
| next if Rails.env.test? | ||
|
|
||
| # Clone the main Rails logger to dissociate it from the other module loggers | ||
| # so we don't receive database, background job and mailer logs | ||
| Rails.logger = Rails.logger.clone | ||
|
|
||
| stdout_logger = ActiveSupport::Logger.new(STDOUT) | ||
|
|
||
| # By default, use a log level of at least 1 so we don't receive debug messages | ||
| stdout_logger.level = args.fetch(:log_level) do | ||
| ENV.fetch('LOG_LEVEL') { [ Rails.logger.level, 1 ].max } | ||
| end | ||
| stdout_logger.formatter = Rails.logger.formatter | ||
|
|
||
| Rails.logger.extend(ActiveSupport::Logger.broadcast(stdout_logger)) | ||
| end |
This file contains hidden or 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,17 @@ | ||
| require 'rails_helper' | ||
| require 'rake' | ||
|
|
||
| RSpec.describe 'cron:day', type: :rake do | ||
| before :all do | ||
| Rake.application.rake_require 'tasks/cron/day' | ||
| Rake::Task.define_task :log_to_stdout | ||
| end | ||
|
|
||
| before { Rake::Task['cron:day'].reenable } | ||
|
|
||
| it 'calls the UpdateSlugs lev routine' do | ||
| expect(UpdateSlugs).to receive(:call) | ||
|
|
||
| Rake.application.invoke_task 'cron:day' | ||
| end | ||
| end |
This file contains hidden or 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,20 @@ | ||
| require 'rails_helper' | ||
| require 'rake' | ||
|
|
||
| RSpec.describe 'cron:minute', type: :rake do | ||
| before :all do | ||
| Rake.application.rake_require 'tasks/cron/minute' | ||
| Rake::Task.define_task :log_to_stdout | ||
| end | ||
|
|
||
| before { Rake::Task['cron:minute'].reenable } | ||
|
|
||
| let!(:task) { instance_double(Rake::Task) } | ||
|
|
||
| it 'calls the openstax:accounts:sync rake task' do | ||
| expect(Rake::Task).to receive(:[]).with('openstax:accounts:sync:accounts').and_return(task) | ||
| expect(task).to receive(:invoke) | ||
|
|
||
| Rake.application.invoke_task 'cron:minute' | ||
| end | ||
| end |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,17 @@ | ||
| require 'rails_helper' | ||
|
|
||
| RSpec.describe UpdateSlugs, type: :routine do | ||
| let!(:exercise) { FactoryBot.create :exercise } | ||
| let!(:updated_exercise) { FactoryBot.create :exercise } | ||
|
|
||
| before do | ||
| allow_any_instance_of(Exercise).to( | ||
| receive(:set_slug_tags!) { |exercise| exercise.id == updated_exercise.id } | ||
| ) | ||
| end | ||
|
|
||
| it 'calls set_slug_tags! on all exercises and sets updated_at for updated exercises' do | ||
| expect { described_class.call }.to change { updated_exercise.reload.updated_at } | ||
| .and not_change { exercise.reload.updated_at } | ||
| end | ||
| end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
At first I thought this might be too often but it seems to only check for updates and seems quick.