Skip to content

Commit

Permalink
Add a task name for the AchievementNotification.pm task and other min…
Browse files Browse the repository at this point in the history
…or cleanup.
  • Loading branch information
drgrice1 committed Dec 5, 2023
1 parent dc9221f commit ef3863f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
15 changes: 7 additions & 8 deletions lib/Mojolicious/WeBWorK/Tasks/AchievementNotification.pm
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,25 @@ sub run ($job, $mail_data) {
return $job->fail("Could not construct course environment for $mail_data->{courseName}.")
unless $ce;

$job->{language_handle} =
WeBWorK::Localize::getLoc($ce->{language} || 'en');
$job->{language_handle} = WeBWorK::Localize::getLoc($ce->{language} || 'en');

my $db = WeBWorK::DB->new($ce->{dbLayout});
return $job->fail($job->maketext("Could not obtain database connection for [_1].", $mail_data->{courseName}))
return $job->fail($job->maketext('Could not obtain database connection for [_1].', $mail_data->{courseName}))
unless $db;

return $job->fail($job->maketext("Cannot notify student without an achievement."))
return $job->fail($job->maketext('Cannot notify student without an achievement.'))
unless $mail_data->{achievementID};
$mail_data->{achievement} = $db->getAchievement($mail_data->{achievementID});
return $job->fail($job->maketext("Could not find achievement [_1].", $mail_data->{achievementID}))
return $job->fail($job->maketext('Could not find achievement [_1].', $mail_data->{achievementID}))
unless $mail_data->{achievement};

my $result_message = eval { $job->send_achievement_notification($ce, $db, $mail_data) };
if ($@) {
$job->app->log->error($job->maketext("An error occurred while trying to send email: $@"));
return $job->fail($job->maketext("An error occurred while trying to send email: [_1]", $@));
$job->app->log->error("An error occurred while trying to send email: $@");
return $job->fail($job->maketext('An error occurred while trying to send email: [_1]', $@));
}
$job->app->log->info("Message sent to $mail_data->{recipient}");
return $job->finish($job->maketext("Message sent to [_1]", $mail_data->{recipient}));
return $job->finish($result_message);
}

sub send_achievement_notification ($job, $ce, $db, $mail_data) {
Expand Down
5 changes: 3 additions & 2 deletions lib/WeBWorK/ContentGenerator/Instructor/JobManager.pm
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ use constant ACTION_FORMS => [ [ filter => x('Filter') ], [ sort => x('Sort') ],

# All tasks added in the Mojolicious::WeBWorK module need to be listed here.
use constant TASK_NAMES => {
lti_mass_update => x('LTI Mass Update'),
send_instructor_email => x('Send Instructor Email')
lti_mass_update => x('LTI Mass Update'),
send_instructor_email => x('Send Instructor Email'),
send_achievement_email => x('Send Achiement Email')
};

# This constant is not used. It is here so that gettext adds these strings to the translation files.
Expand Down

0 comments on commit ef3863f

Please sign in to comment.