mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
Merge pull request #53418 from nextcloud/fix/timedjob-execution-time
Fix TimedJob execution time to allow job execution exactly when scheduled
This commit is contained in:
commit
d67396f1b3
4 changed files with 36 additions and 4 deletions
|
|
@ -40,8 +40,9 @@ class UserStatusAutomation extends TimedJob {
|
|||
) {
|
||||
parent::__construct($timeFactory);
|
||||
|
||||
// Interval 0 might look weird, but the last_checked is always moved
|
||||
// to the next time we need this and then it's 0 seconds ago.
|
||||
// interval = 0 might look odd, but it's intentional. last_run is set to
|
||||
// the user's next available time, so the job runs immediately when
|
||||
// that time comes.
|
||||
$this->setInterval(0);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,12 +9,14 @@ declare(strict_types=1);
|
|||
|
||||
namespace OCA\DAV\Listener;
|
||||
|
||||
use OCA\DAV\BackgroundJob\UserStatusAutomation;
|
||||
use OCA\DAV\CalDAV\CalDavBackend;
|
||||
use OCA\DAV\CardDAV\CardDavBackend;
|
||||
use OCA\DAV\CardDAV\SyncService;
|
||||
use OCA\DAV\Service\ExampleContactService;
|
||||
use OCA\DAV\Service\ExampleEventService;
|
||||
use OCP\Accounts\UserUpdatedEvent;
|
||||
use OCP\BackgroundJob\IJobList;
|
||||
use OCP\Defaults;
|
||||
use OCP\EventDispatcher\Event;
|
||||
use OCP\EventDispatcher\IEventListener;
|
||||
|
|
@ -49,6 +51,7 @@ class UserEventsListener implements IEventListener {
|
|||
private ExampleContactService $exampleContactService,
|
||||
private ExampleEventService $exampleEventService,
|
||||
private LoggerInterface $logger,
|
||||
private IJobList $jobList,
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
@ -124,6 +127,8 @@ class UserEventsListener implements IEventListener {
|
|||
$this->cardDav->deleteAddressBook($addressBook['id']);
|
||||
}
|
||||
|
||||
$this->jobList->remove(UserStatusAutomation::class, ['userId' => $uid]);
|
||||
|
||||
unset($this->calendarsToDelete[$uid]);
|
||||
unset($this->subscriptionsToDelete[$uid]);
|
||||
unset($this->addressBooksToDelete[$uid]);
|
||||
|
|
|
|||
|
|
@ -10,12 +10,14 @@ declare(strict_types=1);
|
|||
|
||||
namespace OCA\DAV\Tests\unit\DAV\Listener;
|
||||
|
||||
use OCA\DAV\BackgroundJob\UserStatusAutomation;
|
||||
use OCA\DAV\CalDAV\CalDavBackend;
|
||||
use OCA\DAV\CardDAV\CardDavBackend;
|
||||
use OCA\DAV\CardDAV\SyncService;
|
||||
use OCA\DAV\Listener\UserEventsListener;
|
||||
use OCA\DAV\Service\ExampleContactService;
|
||||
use OCA\DAV\Service\ExampleEventService;
|
||||
use OCP\BackgroundJob\IJobList;
|
||||
use OCP\Defaults;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
|
|
@ -46,6 +48,7 @@ class UserEventsListenerTest extends TestCase {
|
|||
$this->exampleContactService = $this->createMock(ExampleContactService::class);
|
||||
$this->exampleEventService = $this->createMock(ExampleEventService::class);
|
||||
$this->logger = $this->createMock(LoggerInterface::class);
|
||||
$this->jobList = $this->createMock(IJobList::class);
|
||||
|
||||
$this->userEventsListener = new UserEventsListener(
|
||||
$this->userManager,
|
||||
|
|
@ -56,6 +59,7 @@ class UserEventsListenerTest extends TestCase {
|
|||
$this->exampleContactService,
|
||||
$this->exampleEventService,
|
||||
$this->logger,
|
||||
$this->jobList,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -153,4 +157,27 @@ class UserEventsListenerTest extends TestCase {
|
|||
$this->userEventsListener->preDeleteUser($user);
|
||||
$this->userEventsListener->postDeleteUser('newUser');
|
||||
}
|
||||
|
||||
public function testDeleteUserAutomationEvent(): void {
|
||||
$user = $this->createMock(IUser::class);
|
||||
$user->expects($this->once())->method('getUID')->willReturn('newUser');
|
||||
|
||||
$this->syncService->expects($this->once())
|
||||
->method('deleteUser');
|
||||
|
||||
$this->calDavBackend->expects($this->once())->method('getUsersOwnCalendars')->willReturn([
|
||||
['id' => []]
|
||||
]);
|
||||
$this->calDavBackend->expects($this->once())->method('getSubscriptionsForUser')->willReturn([
|
||||
['id' => []]
|
||||
]);
|
||||
$this->cardDavBackend->expects($this->once())->method('getUsersOwnAddressBooks')->willReturn([
|
||||
['id' => []]
|
||||
]);
|
||||
|
||||
$this->jobList->expects(self::once())->method('remove')->with(UserStatusAutomation::class, ['userId' => 'newUser']);
|
||||
|
||||
$this->userEventsListener->preDeleteUser($user);
|
||||
$this->userEventsListener->postDeleteUser('newUser');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,8 +32,7 @@ class ClearOldStatusesBackgroundJob extends TimedJob {
|
|||
) {
|
||||
parent::__construct($time);
|
||||
|
||||
// Run every time the cron is run
|
||||
$this->setInterval(0);
|
||||
$this->setInterval(60);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue