From a78147e9507307aa5c93c333dfb0e4fc64021bbe Mon Sep 17 00:00:00 2001 From: Jure Grabnar Date: Wed, 27 Feb 2019 14:34:20 +0100 Subject: [PATCH 1/2] update_all_templates task now executes jobs in background --- lib/tasks/data.rake | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/tasks/data.rake b/lib/tasks/data.rake index 0808340ea..6fb5f4971 100644 --- a/lib/tasks/data.rake +++ b/lib/tasks/data.rake @@ -131,12 +131,25 @@ namespace :data do end desc 'Update all templates projects' - task update_all_templates: :environment do + task :update_all_templates, + %i(slice_size) => [:environment] do |_, args| + args.with_defaults(slice_size: 800) + Rails.logger.info('Templates, syncing all templates projects') - updated, total = TemplatesService.new.update_all_templates - Rails.logger.info( - "Templates, total number of updated projects: #{updated} out of #{total}}" - ) + Team.all.order(updated_at: :desc) + .each_slice(args[:slice_size].to_i).with_index do |teams, i| + Rails.logger.info("Processing slice with index #{i}. " \ + "First team: #{teams.first.id}, " \ + "Last team: #{teams.last.id}.") + + teams.each do |team| + TemplatesService.new.delay( + run_at: i.hours.from_now, + queue: :templates, + priority: 1 + ).update_team(team) + end + end end desc 'Create demo project on existing users' From 8025acc2d7a1e3e62136978419c3155ad5819800 Mon Sep 17 00:00:00 2001 From: Jure Grabnar Date: Wed, 27 Feb 2019 14:46:12 +0100 Subject: [PATCH 2/2] Update the priority for the templates background generation --- lib/tasks/data.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/data.rake b/lib/tasks/data.rake index 6fb5f4971..9affbd359 100644 --- a/lib/tasks/data.rake +++ b/lib/tasks/data.rake @@ -146,7 +146,7 @@ namespace :data do TemplatesService.new.delay( run_at: i.hours.from_now, queue: :templates, - priority: 1 + priority: 5 ).update_team(team) end end