Skip to content

Commit d67396f

Browse files
Merge pull request #53418 from nextcloud/fix/timedjob-execution-time
Fix TimedJob execution time to allow job execution exactly when scheduled
2 parents 11f0a5f + 289b7ab commit d67396f

4 files changed

Lines changed: 36 additions & 4 deletions

File tree

apps/dav/lib/BackgroundJob/UserStatusAutomation.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ public function __construct(
4040
) {
4141
parent::__construct($timeFactory);
4242

43-
// Interval 0 might look weird, but the last_checked is always moved
44-
// to the next time we need this and then it's 0 seconds ago.
43+
// interval = 0 might look odd, but it's intentional. last_run is set to
44+
// the user's next available time, so the job runs immediately when
45+
// that time comes.
4546
$this->setInterval(0);
4647
}
4748

apps/dav/lib/Listener/UserEventsListener.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99

1010
namespace OCA\DAV\Listener;
1111

12+
use OCA\DAV\BackgroundJob\UserStatusAutomation;
1213
use OCA\DAV\CalDAV\CalDavBackend;
1314
use OCA\DAV\CardDAV\CardDavBackend;
1415
use OCA\DAV\CardDAV\SyncService;
1516
use OCA\DAV\Service\ExampleContactService;
1617
use OCA\DAV\Service\ExampleEventService;
1718
use OCP\Accounts\UserUpdatedEvent;
19+
use OCP\BackgroundJob\IJobList;
1820
use OCP\Defaults;
1921
use OCP\EventDispatcher\Event;
2022
use OCP\EventDispatcher\IEventListener;
@@ -49,6 +51,7 @@ public function __construct(
4951
private ExampleContactService $exampleContactService,
5052
private ExampleEventService $exampleEventService,
5153
private LoggerInterface $logger,
54+
private IJobList $jobList,
5255
) {
5356
}
5457

@@ -124,6 +127,8 @@ public function postDeleteUser(string $uid): void {
124127
$this->cardDav->deleteAddressBook($addressBook['id']);
125128
}
126129

130+
$this->jobList->remove(UserStatusAutomation::class, ['userId' => $uid]);
131+
127132
unset($this->calendarsToDelete[$uid]);
128133
unset($this->subscriptionsToDelete[$uid]);
129134
unset($this->addressBooksToDelete[$uid]);

apps/dav/tests/unit/DAV/Listener/UserEventsListenerTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010

1111
namespace OCA\DAV\Tests\unit\DAV\Listener;
1212

13+
use OCA\DAV\BackgroundJob\UserStatusAutomation;
1314
use OCA\DAV\CalDAV\CalDavBackend;
1415
use OCA\DAV\CardDAV\CardDavBackend;
1516
use OCA\DAV\CardDAV\SyncService;
1617
use OCA\DAV\Listener\UserEventsListener;
1718
use OCA\DAV\Service\ExampleContactService;
1819
use OCA\DAV\Service\ExampleEventService;
20+
use OCP\BackgroundJob\IJobList;
1921
use OCP\Defaults;
2022
use OCP\IUser;
2123
use OCP\IUserManager;
@@ -46,6 +48,7 @@ protected function setUp(): void {
4648
$this->exampleContactService = $this->createMock(ExampleContactService::class);
4749
$this->exampleEventService = $this->createMock(ExampleEventService::class);
4850
$this->logger = $this->createMock(LoggerInterface::class);
51+
$this->jobList = $this->createMock(IJobList::class);
4952

5053
$this->userEventsListener = new UserEventsListener(
5154
$this->userManager,
@@ -56,6 +59,7 @@ protected function setUp(): void {
5659
$this->exampleContactService,
5760
$this->exampleEventService,
5861
$this->logger,
62+
$this->jobList,
5963
);
6064
}
6165

@@ -153,4 +157,27 @@ public function testDeleteCalendar(): void {
153157
$this->userEventsListener->preDeleteUser($user);
154158
$this->userEventsListener->postDeleteUser('newUser');
155159
}
160+
161+
public function testDeleteUserAutomationEvent(): void {
162+
$user = $this->createMock(IUser::class);
163+
$user->expects($this->once())->method('getUID')->willReturn('newUser');
164+
165+
$this->syncService->expects($this->once())
166+
->method('deleteUser');
167+
168+
$this->calDavBackend->expects($this->once())->method('getUsersOwnCalendars')->willReturn([
169+
['id' => []]
170+
]);
171+
$this->calDavBackend->expects($this->once())->method('getSubscriptionsForUser')->willReturn([
172+
['id' => []]
173+
]);
174+
$this->cardDavBackend->expects($this->once())->method('getUsersOwnAddressBooks')->willReturn([
175+
['id' => []]
176+
]);
177+
178+
$this->jobList->expects(self::once())->method('remove')->with(UserStatusAutomation::class, ['userId' => 'newUser']);
179+
180+
$this->userEventsListener->preDeleteUser($user);
181+
$this->userEventsListener->postDeleteUser('newUser');
182+
}
156183
}

apps/user_status/lib/BackgroundJob/ClearOldStatusesBackgroundJob.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ public function __construct(
3232
) {
3333
parent::__construct($time);
3434

35-
// Run every time the cron is run
36-
$this->setInterval(0);
35+
$this->setInterval(60);
3736
}
3837

3938
/**

0 commit comments

Comments
 (0)