Skip to content

Commit a170cbf

Browse files
author
Martin Krulis
committed
Fixing assignment deadline notifications so that hidden assignments are not considered. The parametrization of the command was slightly modified.
1 parent 8e96782 commit a170cbf

File tree

4 files changed

+37
-17
lines changed

4 files changed

+37
-17
lines changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,18 @@ notifications of assignment deadlines and cleaning up uploaded files. The
8484
recommended way of ensuring this is using a crontab like this:
8585

8686
```
87-
04 00 * * * php www/index.php notifications:assignment-deadlines "1 day"
88-
02 00 * * * php www/index.php db:cleanup:uploads
87+
00 03 * * 6 php www/index.php db:cleanup:uploads
88+
15 03 * * 6 php www/index.php db:cleanup:exercise-configs
89+
30 03 * * 6 php www/index.php db:cleanup:localized-texts
90+
45 03 * * 6 php www/index.php db:cleanup:pipeline-configs
91+
00 04 * * * php www/index.php notifications:assignment-deadlines
8992
```
9093

94+
The example above will send email notifications at 4 a.m. every day and perform database garbage collection tasks between 3 and 4 a.m. every Saturday.
95+
96+
Some details of these periodic commands (e.g., a threshold period of relevant assignment deadlines) can be configured in api neon config file.
97+
98+
9199
## Adminer
92100

93101
[Adminer](https://www.adminer.org/) is full-featured database management tool written in PHP and it is part of this Sandbox.

app/commands/SendAssignmentDeadlineNotification.php

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,40 @@ class SendAssignmentDeadlineNotification extends Command {
1717
private $assignments;
1818

1919
/** @var string */
20-
private $threshold;
20+
private $thresholdFrom;
2121

22-
public function __construct(string $threshold, Assignments $assignments, AssignmentEmailsSender $sender) {
22+
/** @var string */
23+
private $thresholdTo;
24+
25+
public function __construct(string $thresholdFrom, string $thresholdTo, Assignments $assignments, AssignmentEmailsSender $sender) {
2326
parent::__construct();
2427
$this->sender = $sender;
2528
$this->assignments = $assignments;
26-
$this->threshold = $threshold;
29+
$this->thresholdFrom = $thresholdFrom;
30+
$this->thresholdTo = $thresholdTo;
2731
}
2832

2933
protected function configure() {
3034
$this->setName('notifications:assignment-deadlines')->setDescription('Send notifications for assignments with imminent deadlines.');
31-
$this->addArgument("period", InputArgument::REQUIRED, "How often is the script run (e.g. '1 day')");
3235
}
3336

3437
protected function execute(InputInterface $input, OutputInterface $output) {
35-
$period = $input->getArgument("period");
36-
3738
$from = new DateTime();
38-
$from->modify("+" . $this->threshold);
39-
$to = clone $from;
40-
$to->modify("+" . $period);
39+
if ($this->thresholdFrom) {
40+
$from->modify($this->thresholdFrom);
41+
}
42+
$to = new DateTime();
43+
if ($this->thresholdTo) {
44+
$to->modify($this->thresholdTo);
45+
}
46+
if ($from > $to) {
47+
$tmp = $from; $from = $to; $to = $tmp; // swap
48+
}
4149

4250
foreach ($this->assignments->findByDeadline($from, $to) as $assignment) {
43-
$this->sender->assignmentDeadline($assignment);
51+
if ($assignment->isPublic()) {
52+
$this->sender->assignmentDeadline($assignment);
53+
}
4454
}
4555

4656
return 0;

app/config/config.neon

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ parameters:
108108
from: %emails.from%
109109
newAssignmentPrefix: "New Assignment -"
110110
assignmentDeadlinePrefix: "Assignment Deadline Is Behind the Corner -"
111-
assignmentDeadlineThreshold: 1 day
111+
assignmentDeadlineThresholdFrom: +1 day
112+
assignmentDeadlineThresholdTo: +2 days
112113

113114
submissionNotifications:
114115
emails:
@@ -241,7 +242,7 @@ services:
241242
- App\Console\DoctrineFixtures
242243
- App\Console\GenerateSwagger(@router)
243244
- App\Console\CleanupUploads
244-
- App\Console\SendAssignmentDeadlineNotification(%assignmentNotifications.emails.assignmentDeadlineThreshold%)
245+
- App\Console\SendAssignmentDeadlineNotification(%assignmentNotifications.emails.assignmentDeadlineThresholdFrom%, %assignmentNotifications.emails.assignmentDeadlineThresholdTo%)
245246
- App\Console\ExportDatabase
246247
- App\Console\CleanupLocalizedTexts
247248
- App\Console\CleanupExerciseConfigs

tests/Console/DeadlineNotifications.phpt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class TestDeadlineNotifications extends Tester\TestCase
7373
$this->assignmentSolutions = $this->container->getByType(AssignmentSolutions::class);
7474
$this->sender = new AssignmentEmailsSender($this->emailHelperMock, $this->assignmentSolutions, []);
7575
$this->command = new SendAssignmentDeadlineNotification(
76+
"",
7677
"1 day",
7778
$this->assignments,
7879
$this->sender
@@ -92,7 +93,7 @@ class TestDeadlineNotifications extends Tester\TestCase
9293
$this->assignments->persist($assignment);
9394

9495
$this->emailHelperMock->shouldNotReceive("send");
95-
$input = new StringInput("'1 day'");
96+
$input = new StringInput("");
9697
$this->command->run($input, new NullOutput());
9798

9899
Assert::true(true); // We make no assertions here - all the work is done by Mockery
@@ -102,12 +103,12 @@ class TestDeadlineNotifications extends Tester\TestCase
102103
$assignment = Assignment::assignToGroup($this->demoExercise, $this->demoGroup, true);
103104

104105
$deadline = new DateTime();
105-
$deadline->modify("+36 hours");
106+
$deadline->modify("+12 hours");
106107
$assignment->setFirstDeadline($deadline);
107108
$this->assignments->persist($assignment);
108109

109110
$this->emailHelperMock->shouldReceive("send")->once()->andReturn(true);
110-
$input = new StringInput("'1 day'");
111+
$input = new StringInput("");
111112
$this->command->run($input, new NullOutput());
112113

113114
Assert::true(true); // We make no assertions here - all the work is done by Mockery

0 commit comments

Comments
 (0)