Skip to content
Snippets Groups Projects
Commit f02dc2a7 authored by Israel Barreto Sant'Anna's avatar Israel Barreto Sant'Anna
Browse files

Created worker to delete attachment bitstream

parent 0868ffcd
No related branches found
No related tags found
No related merge requests found
......@@ -6,7 +6,7 @@ class V1::LearningObjects::AttachmentController < ApplicationController
def destroy
return render status: :not_found if @learning_object.nil? || @attachment.nil?
destroy_attachment_in_dspace(@attachment.id_dspace)
DeleteBitstreamWorker.perform_async(@attachment.id)
@attachment.destroy
render status: :ok
......@@ -28,9 +28,4 @@ class V1::LearningObjects::AttachmentController < ApplicationController
authorize(@learning_object, :destroy?)
end
def destroy_attachment_in_dspace(id)
client = DspaceService.create_client
client.bitstreams.delete(id: id)
end
end
require_dependency 'dspace'
class DeleteBitstreamWorker
include Sidekiq::Worker
def perform(attachment_id = nil)
attachment = LearningObject::Attachment.find(attachment_id)
return false if attachment.blank? || !wait_bitstream(attachment)
DspaceService.create_client.bitstreams.delete(id: attachment.id_dspace)
end
private
def wait_bitstream(attachment)
if attachment.id_dspace.blank?
Timeout.timeout(60) do
sleep(1.0) while attachment.id_dspace.blank?
end
end
true
rescue Timeout::Error
false
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment