prevent serializing TII client (procs)
fixes FOO-1230 flag=none TEST PLAN: 1) new up a processor 2) access it's client (set the ivar for tii) 3) call "#resubmit" with a submission and asset string 4) serialized object should not have the TII client inside it. Change-Id: I99257986f730838b6bda2254fec11edad935ea61 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/253573 Reviewed-by: Cody Cutrer <cody@instructure.com> Product-Review: Cody Cutrer <cody@instructure.com> Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> QA-Review: Ethan Vizitei <evizitei@instructure.com>
This commit is contained in:
parent
5ee68917a5
commit
5b3924edd2
|
@ -62,18 +62,22 @@ module Turnitin
|
|||
# exponential backoff. We should add
|
||||
# one to give TII more time to process
|
||||
# attachments.
|
||||
delay(max_attempts: self.class.max_attempts).update_originality_data(submission, asset_string)
|
||||
stash_turnitin_client do
|
||||
delay(max_attempts: self.class.max_attempts).update_originality_data(submission, asset_string)
|
||||
end
|
||||
rescue Errors::ScoreStillPendingError
|
||||
if attempt_number == self.class.max_attempts
|
||||
create_error_attachment
|
||||
raise
|
||||
else
|
||||
turnitin_processor = Turnitin::OutcomeResponseProcessor.new(@tool, @assignment, @user, @outcomes_response_json)
|
||||
turnitin_processor.delay(max_attempts: Turnitin::OutcomeResponseProcessor.max_attempts,
|
||||
priority: Delayed::LOW_PRIORITY,
|
||||
attempts: attempt_number,
|
||||
run_at: Time.now.utc + (attempt_number ** 4) + 5).
|
||||
process
|
||||
stash_turnitin_client do
|
||||
turnitin_processor.delay(max_attempts: Turnitin::OutcomeResponseProcessor.max_attempts,
|
||||
priority: Delayed::LOW_PRIORITY,
|
||||
attempts: attempt_number,
|
||||
run_at: Time.now.utc + (attempt_number ** 4) + 5).
|
||||
process
|
||||
end
|
||||
end
|
||||
rescue StandardError
|
||||
if attempt_number == self.class.max_attempts
|
||||
|
@ -83,7 +87,9 @@ module Turnitin
|
|||
end
|
||||
|
||||
def resubmit(submission, asset_string)
|
||||
delay(max_attempts: self.class.max_attempts).update_originality_data(submission, asset_string)
|
||||
stash_turnitin_client do
|
||||
delay(max_attempts: self.class.max_attempts).update_originality_data(submission, asset_string)
|
||||
end
|
||||
end
|
||||
|
||||
def turnitin_client
|
||||
|
@ -112,11 +118,6 @@ module Turnitin
|
|||
end
|
||||
end
|
||||
|
||||
# dont try and recreate the turnitin client in a delayed job. bad things happen
|
||||
def delay(**)
|
||||
stash_turnitin_client { super }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def create_error_attachment
|
||||
|
@ -128,6 +129,13 @@ module Turnitin
|
|||
)
|
||||
end
|
||||
|
||||
# the turnitin client has a proc embedded
|
||||
# in it's faraday connection. If you try to serialize it,
|
||||
# it will fail to deserialize (for good reason, closures can't
|
||||
# take the whole state of the system with them when written
|
||||
# as yaml). This method un-sets the ivar long enough to
|
||||
# serialize the object for job processing (a turnitin client
|
||||
# will be created in the job when necessary).
|
||||
def stash_turnitin_client
|
||||
old_turnit_client = @_turnitin_client
|
||||
@_turnitin_client = nil
|
||||
|
|
|
@ -171,5 +171,15 @@ module Turnitin
|
|||
expect(submission.turnitin_data[attachment.asset_string][:public_error_message]).to start_with "Turnitin has not"
|
||||
end
|
||||
end
|
||||
|
||||
describe "#resubmit" do
|
||||
it "doesn't serialize the whole TII client" do
|
||||
expect(subject.turnitin_client).to_not be_nil
|
||||
submission = Submission.new(id: 1)
|
||||
output_job = subject.resubmit(submission, "asset_string")
|
||||
output_job = Delayed::Job.where(tag: "Turnitin::OutcomeResponseProcessor#update_originality_data").last
|
||||
expect(output_job.handler).to_not include("ruby/object:Turnitin::TiiClient")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue