Created
January 30, 2017 12:52
-
-
Save paderinandrey/f77c12ab75dc57d203317175a4b326ca to your computer and use it in GitHub Desktop.
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
class CloneCourse < ActiveJob::Base | |
def perform(course) | |
ActiveRecord::Base.transaction do | |
@new_course = course.dup | |
@new_course.save! | |
course.materials.each do |material| | |
@new_material = material.dup | |
@new_material.course = @new_course | |
@new_material.save! | |
copy_file(material, @new_material) | |
end | |
end | |
end | |
private | |
def copy_file(material, new_material) | |
s3 = AWS::S3.new(material.file.s3_credentials) | |
s3_file = s3.buckets[material.file.s3_credentials[:bucket]].objects.first | |
s3_file.copy_to(new_material.file.s3_object) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment