From 8973de44403e605c338ffe68af1c7fba7a76dbf2 Mon Sep 17 00:00:00 2001 From: Glenn Rice Date: Mon, 23 Oct 2023 07:56:28 -0500 Subject: [PATCH] Capture logs for the LTIMassUpdate task and return them for the job result. Note that the job will still succeed but now some failures/messages will appear in the job result. If `debug_lti_grade_passback` or `debug_lti_parameters` are enabled then the job result will now be rather extensive. Everything that is sent to the log will be in result. --- lib/Mojolicious/WeBWorK/Tasks/LTIMassUpdate.pm | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/Mojolicious/WeBWorK/Tasks/LTIMassUpdate.pm b/lib/Mojolicious/WeBWorK/Tasks/LTIMassUpdate.pm index e112f5231e..ab1c94c621 100644 --- a/lib/Mojolicious/WeBWorK/Tasks/LTIMassUpdate.pm +++ b/lib/Mojolicious/WeBWorK/Tasks/LTIMassUpdate.pm @@ -39,6 +39,14 @@ sub run ($job, $userID = '', $setID = '') { my $db = WeBWorK::DB->new($ce->{dbLayout}); return $job->fail($job->maketext('Could not obtain database connection.')) unless $db; + my @messages; + $job->app->log->on( + message => sub { + my ($log, $level, @lines) = @_; + push @messages, $lines[-1]; + } + ); + # Pass a fake controller object that will work for the grader. my $grader = $ce->{LTIVersion} eq 'v1p1' @@ -72,14 +80,16 @@ sub run ($job, $userID = '', $setID = '') { } if ($setID && $userID && $ce->{LTIGradeMode} eq 'homework') { - return $job->finish($job->maketext('Updated grades via LTI for user [_1] and set [_2].', $userID, $setID)); + unshift(@messages, $job->maketext('Updated grades via LTI for user [_1] and set [_2].', $userID, $setID)); } elsif ($setID && $ce->{LTIGradeMode} eq 'homework') { - return $job->finish($job->maketext('Updated grades via LTI all users assigned to set [_1].', $setID)); + unshift(@messages, $job->maketext('Updated grades via LTI all users assigned to set [_1].', $setID)); } elsif ($userID) { - return $job->finish($job->maketext('Updated grades via LTI of all sets assigned to user [_1].', $userID)); + unshift(@messages, $job->maketext('Updated grades via LTI of all sets assigned to user [_1].', $userID)); } else { - return $job->finish($job->maketext('Updated grades via LTI for all sets and users.')); + unshift(@messages, $job->maketext('Updated grades via LTI for all sets and users.')); } + + return $job->finish(@messages > 1 ? \@messages : $messages[0]); } sub maketext ($job, @args) {