Skip to content

Commit

Permalink
Revise sending SR notifications assuming whole hour deadlines (#988)
Browse files Browse the repository at this point in the history
  • Loading branch information
70ray authored Feb 9, 2024
1 parent 4450ebc commit 5cdbc6f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 31 deletions.
2 changes: 1 addition & 1 deletion SETUP/dp.cron.template
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# hourly:
03 * * * * URL=<<CODE_URL>>/crontab/update_user_counts.php; <<URL_DUMP_PROGRAM>> $URL
55 * * * * URL=<<CODE_URL>>/crontab/finish_smoothreading.php; <<URL_DUMP_PROGRAM>> $URL
05 * * * * URL=<<CODE_URL>>/crontab/finish_smoothreading.php; <<URL_DUMP_PROGRAM>> $URL

# daily:
01 0 * * * URL=<<CODE_URL>>/crontab/take_tally_snapshots.php; <<URL_DUMP_PROGRAM>> $URL
Expand Down
43 changes: 13 additions & 30 deletions crontab/finish_smoothreading.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,55 +14,38 @@
echo "This is a dry run.\n";
}

// Interval relative to current time
// Select all projects whose smooth reading deadline is within this interval.
// This should run at 5 minutes past each hour
// Assume smooth read deadlines are at exact hours
// Select all projects whose smooth reading deadline is within the past hour.
$from = -60 * 60;
$to = 60 * 60;

$sql = sprintf(
"
SELECT *
FROM projects
WHERE
smoothread_deadline >= (UNIX_TIMESTAMP() + %d)
AND smoothread_deadline <= (UNIX_TIMESTAMP() + %d)
AND smoothread_deadline <= UNIX_TIMESTAMP()
AND state = '%s'
",
$from,
$to,
DPDatabase::escape(PROJ_POST_FIRST_CHECKED_OUT)
);
$result = DPDatabase::query($sql);

$output = "Checking " . mysqli_num_rows($result) . " projects...\n";
$any_work_done = false;

// Used for checking smoothread_deadline within the loop
$curr_time = date('Y-m-d H');

while ($row = mysqli_fetch_assoc($result)) {
$project = new Project($row);

// Check if the time is right, with precision of an hour
$deadline = date('Y-m-d H', $project->smoothread_deadline);

if ($curr_time == $deadline) {
$output .= "$project->nameofwork\n";
$any_work_done = true;
$number_of_projects = mysqli_num_rows($result);

if ($number_of_projects > 0) {
echo "Found $number_of_projects projects...\n";
while ($row = mysqli_fetch_assoc($result)) {
$project = new Project($row);
echo "$project->nameofwork\n";
if ($dry_run) {
$output .= " Since this is a dry run, we won't send an email and log an event\n";
echo " Since this is a dry run, we won't send an email and log an event\n";
} else {
$output .= " Sending email and logging event...\n";
echo " Sending email and logging event...\n";
$project->log_project_event('[AUTO]', 'smooth-reading', 'finished');
notify_project_event_subscribers($project, 'sr_complete');
}
}
}

$output .= "finish_smoothreading.php executed.\n";

// Don't output anything if no work was done
if ($any_work_done) {
echo $output;
echo "finish_smoothreading.php executed.\n";
}

0 comments on commit 5cdbc6f

Please sign in to comment.