2022-12-02 16:45:02 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module MyModules
|
|
|
|
class CopyContentJob < ApplicationJob
|
2023-08-11 21:31:29 +08:00
|
|
|
def perform(user_id, source_my_module_id, target_my_module_id)
|
|
|
|
user = User.find(user_id)
|
2023-03-31 23:39:17 +08:00
|
|
|
target_my_module = MyModule.find(target_my_module_id)
|
2022-12-02 16:45:02 +08:00
|
|
|
MyModule.transaction do
|
|
|
|
MyModule.find(source_my_module_id).copy_content(user, target_my_module)
|
2023-01-13 19:48:35 +08:00
|
|
|
create_copy_my_module_activity(user, source_my_module_id, target_my_module_id)
|
2022-12-02 16:45:02 +08:00
|
|
|
target_my_module.update!(provisioning_status: :done)
|
|
|
|
end
|
2023-03-31 23:39:17 +08:00
|
|
|
rescue StandardError => e
|
|
|
|
Rails.logger.error e.message
|
2022-12-02 16:45:02 +08:00
|
|
|
target_my_module.update(provisioning_status: :failed)
|
|
|
|
end
|
2023-01-13 19:48:35 +08:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def create_copy_my_module_activity(user, my_module_original_id, my_module_new_id)
|
|
|
|
my_module_new = MyModule.find(my_module_new_id)
|
|
|
|
Activities::CreateActivityService
|
|
|
|
.call(activity_type: :clone_module,
|
|
|
|
owner: user,
|
|
|
|
team: my_module_new.experiment.project.team,
|
|
|
|
project: my_module_new.experiment.project,
|
|
|
|
subject: my_module_new,
|
|
|
|
message_items: { my_module_original: my_module_original_id,
|
|
|
|
my_module_new: my_module_new.id })
|
|
|
|
end
|
2022-12-02 16:45:02 +08:00
|
|
|
end
|
|
|
|
end
|