mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-26 17:51:13 +08:00
update_all_templates task now executes jobs in background
This commit is contained in:
parent
26f9c596e8
commit
a78147e950
1 changed files with 18 additions and 5 deletions
|
@ -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'
|
||||
|
|
Loading…
Reference in a new issue