-
Notifications
You must be signed in to change notification settings - Fork 3
/
run-enrollments.pl
executable file
·84 lines (68 loc) · 2.42 KB
/
run-enrollments.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/perl
#
# This script launches the process-enrollments script. Depending on what
# host it's run on, what day of the week it is, and what time it is, the
# options are different. A crontab to capture all of this was getting
# too messy and hence we have this script
#
# This script expects to get invoked about hourly and will run the
# enrollment processing with the minimum set of options unless the
# current day/time matches specified patterns
$hostname = `hostname -s`;
chomp($hostname);
$debug = 0;
$stderr = "/tmp/process-enrollments.err";
$stdout = "/tmp/process-enrollments.out";
$cmd = "/opt/amaint/etc/process-enrollments.pl";
$error_email = "canvas-tech-icat\@sfu.ca";
$info_email = "canvas-tech-icat\@sfu.ca";
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
# At 4am, we run with debug=1 to give verbose output
$debug = 1 if ($hour == 4);
$subject = "Results of process-enrollments script on $hostname";
# At 6am, we process missing sections
if ($hour == 6)
{
$sections = 1;
$subject = "Canvas Section Changes on $hostname";
}
# Only run under prod conditions if host is canvas-mp
$prod = 1 if ($hostname =~ /canvas-mp(\d*)/);
# Exit if we're not running on the first canvas-m node
exit 0 if ($1 > 1);
# Exit unless we're running on Prod or it's 4am (stage and test run at 4am only)
exit 0 unless ($hour == 4 || $prod);
# On Sundays, process ALL courses not just non-completed ones
$completed = 1 if ($wday == 0 && $hour == 4);
# We only email the Canvas queue if the stderr output changes between runs
if (-e $stderr)
{
system("mv $stderr $stderr.old");
}
else
{
system("touch $stderr.old");
}
$opts = "-d $debug ";
$opts .= "-s " if ($sections);
$opts .= "-c " if ($completed);
# Run it!
#print("$cmd $opts > $stdout 2> $stderr");
system("$cmd $opts > $stdout 2> $stderr");
# See if STDERR changed between runs
$junk = `diff $stderr.old $stderr > /dev/null 2>&1`;
if ($?)
{
# Files are different, we have new errors
system("cat $stderr | mail -s \"Errors from process-enrollments script on $hostname\" $error_email");
}
# Check to see whether there were any new sections in the output
if ($sections)
{
$junk = `grep "course_id" $stdout`;
$sections = ! $?;
}
# See if script produced any enrollment changes. If not, exit quietly
$junk = `grep "No enrollment changes to process" $stdout`;
exit 0 if (!$sections && $? == 0 );
system("cat $stdout | mail -s \"$subject\" $info_email");