Skip to content

Commit

Permalink
Capture logs for the LTIMassUpdate task and return them for the job r…
Browse files Browse the repository at this point in the history
…esult.

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.
  • Loading branch information
drgrice1 committed Oct 23, 2023
1 parent d492a23 commit 8973de4
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions lib/Mojolicious/WeBWorK/Tasks/LTIMassUpdate.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 8973de4

Please sign in to comment.