scinote-web/lib/tasks/exportable_items.rake

29 lines
954 B
Ruby
Raw Normal View History

2017-03-27 16:02:47 +08:00
namespace :exportable_items do
2017-04-04 16:16:54 +08:00
desc 'Removes exportable zip files'
2017-03-27 16:02:47 +08:00
task cleanup: :environment do
2017-04-04 16:16:54 +08:00
num = Constants::EXPORTABLE_ZIP_EXPIRATION_DAYS
ZipExport.where('created_at < ?', num.days.ago).destroy_all
puts "All exportable zip files older than " \
"'#{num.days.ago}' have been removed"
2017-03-27 16:02:47 +08:00
end
desc 'Resets export project counter to 0'
task reset_export_projects_counter: :environment do
2018-10-15 20:25:12 +08:00
User.find_each do |user|
User.transaction do
begin
user.export_vars['num_of_export_all_last_24_hours'] = 0
user.save
rescue ActiveRecord::ActiveRecordError,
ArgumentError,
ActiveRecord::RecordNotSaved => e
2018-10-15 20:25:12 +08:00
puts "Error resetting users num_of_export_all_last_24_hours " \
"variable to 0, transaction reverted: #{e}"
end
end
end
puts 'Export project counter successfully ' \
'reset on all users'
end
2017-03-27 16:02:47 +08:00
end