Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revise sending SR notifications assuming whole hour deadlines #988

Merged
merged 2 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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";
cpeel marked this conversation as resolved.
Show resolved Hide resolved
}
Loading