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.

Also add logs back that were removed initially.  Since Minion removes
jobs after two days, the messages in the result are lost with them.  So
also log them so that they are more permanently stored.
  • Loading branch information
drgrice1 committed Oct 23, 2023
1 parent d492a23 commit 4cce50f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
20 changes: 16 additions & 4 deletions lib/Mojolicious/WeBWorK/Tasks/LTIMassUpdate.pm
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ 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;
my $job_logger = sub {
my ($log, $level, @lines) = @_;
push @messages, $lines[-1];
};
$job->app->log->on(message => $job_logger);

# Pass a fake controller object that will work for the grader.
my $grader =
$ce->{LTIVersion} eq 'v1p1'
Expand Down Expand Up @@ -72,14 +79,19 @@ 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.'));
}

$job->app->log->unsubscribe(message => $job_logger);

$job->app->log->info($messages[0]);
return $job->finish(@messages > 1 ? \@messages : $messages[0]);
}

sub maketext ($job, @args) {
Expand Down
6 changes: 4 additions & 2 deletions lib/Mojolicious/WeBWorK/Tasks/SendInstructorEmail.pm
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ sub run ($job, $mail_data) {
if ($@) {
push(@result_messages,
$job->maketext('An error occurred while trying to send email.'),
$job->maketext('The error message is:'),
ref($@) ? $@->message : $@);
$job->maketext('The error message is: [_1]', ref($@) ? $@->message : $@),
);
$job->app->log->error($_) for @result_messages;
return $job->fail(\@result_messages);
}

$job->app->log->error($_) for @result_messages;
return $job->finish(\@result_messages);
}

Expand Down

0 comments on commit 4cce50f

Please sign in to comment.