Skip to content

feat(userEventListeners): add UserEventListener and UserStatsJob - #17

Merged
printminion-co merged 1 commit into
mainfrom
as/dev/NSW-876-user-event-listener
May 13, 2026
Merged

feat(userEventListeners): add UserEventListener and UserStatsJob#17
printminion-co merged 1 commit into
mainfrom
as/dev/NSW-876-user-event-listener

Conversation

@Arsalanulhaq

Copy link
Copy Markdown
Contributor

Listens to UserCreatedEvent and UserDeletedEvent to log synchronous info entries and schedule a one-shot UserStatsJob that collects the total user count and logs the NSW-842 stats payload.

@Arsalanulhaq
Arsalanulhaq force-pushed the as/dev/NSW-876-user-event-listener branch from 1e3bad4 to 4bc604c Compare May 5, 2026 09:38
@Arsalanulhaq
Arsalanulhaq requested a review from Copilot May 5, 2026 10:12

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds user lifecycle telemetry to the NCW Tools app by registering a new UserEventListener for Nextcloud user create/delete events and a UserStatsJob background job that logs aggregate user-count data.

Changes:

  • Added UserEventListener to react to UserCreatedEvent and UserDeletedEvent.
  • Added UserStatsJob to collect total user count and log the stats payload asynchronously.
  • Updated application registration, Psalm config, and unit tests for the new listener/job wiring.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/unit/Listeners/UserEventListenerTest.php Adds unit coverage for create/delete/unsupported event handling.
tests/unit/BackgroundJob/UserStatsJobTest.php Adds unit coverage for success and failure paths of the new background job.
tests/unit/AppInfo/ApplicationTest.php Extends bootstrap registration tests for the new user event listener.
psalm.xml Suppresses possibly-unused constructor warnings for new DI-managed classes.
lib/Listeners/UserEventListener.php Implements the new listener that logs user events and enqueues the stats job.
lib/BackgroundJob/UserStatsJob.php Implements the queued job that logs the user-count payload.
lib/AppInfo/Application.php Registers the new listener for user created/deleted events.

Comment thread lib/Listeners/UserEventListener.php Outdated
@Arsalanulhaq
Arsalanulhaq force-pushed the as/dev/NSW-876-user-event-listener branch from 4bc604c to b88779b Compare May 5, 2026 11:45
@Arsalanulhaq
Arsalanulhaq requested a review from Copilot May 5, 2026 12:13

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment thread lib/Listeners/UserEventListener.php Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Comment thread lib/Listeners/UserEventListener.php Outdated
Comment thread lib/BackgroundJob/UserStatsJob.php Outdated

@bromiesTM bromiesTM left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As Copilot said, the eventlistener does to much. It should just start the background job which handles the stat collection.

@Arsalanulhaq
Arsalanulhaq force-pushed the as/dev/NSW-876-user-event-listener branch from b88779b to f08c24c Compare May 6, 2026 14:23
@printminion-co
printminion-co requested a review from Copilot May 6, 2026 15:00
@bromiesTM
bromiesTM requested review from Copilot and removed request for Copilot May 7, 2026 07:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment thread tests/unit/AppInfo/ApplicationTest.php Outdated
Comment on lines 44 to 52
public function testRegisterMethodExists(): void {
// Test that register method registers the InstallationCompletedEvent listener
$this->registrationContext
->expects($this->once())
->expects($this->exactly(3))
->method('registerEventListener')
->with(
InstallationCompletedEvent::class,
InstallationCompletedEventListener::class
);
->willReturnCallback(function (string $event, string $listener): void {
// no assertions needed; just allow the three calls
});

$this->application->register($this->registrationContext);
@bromiesTM

Copy link
Copy Markdown

@copilot what happens if there are multiple jobs at the same time? They would report the same number of users and therefore it makes no sense to have more at one job at the same time? Is that correct?

Copilot AI commented May 11, 2026

Copy link
Copy Markdown

As Copilot said, the eventlistener does to much. It should just start the background job which handles the stat collection.

Fixed in eccdac3. The listener now only logs the event and enqueues the job — and with the deduplication added, it skips adding a new UserStatsJob if one is already pending in the queue (using IJobList::has()). The job itself still does all the stats collection (user count + timestamp) at run time.

@copilot what happens if there are multiple jobs at the same time? They would report the same number of users and therefore it makes no sense to have more at one job at the same time? Is that correct?...

Yes, exactly right. Multiple queued jobs would all read the same user count when they execute, producing redundant identical log entries. Fixed in eccdac3 by checking IJobList::has(UserStatsJob::class, null) before adding — so at most one UserStatsJob sits in the queue at any time. Once cron picks it up and it runs, the next user event will queue a fresh job.

Copilot AI requested a review from bromiesTM May 11, 2026 07:10
@bromiesTM
bromiesTM force-pushed the as/dev/NSW-876-user-event-listener branch from eccdac3 to 6078837 Compare May 11, 2026 08:45
@printminion-co
printminion-co force-pushed the as/dev/NSW-876-user-event-listener branch from 6078837 to cfad0e8 Compare May 13, 2026 14:45
@printminion-co
printminion-co requested a review from Copilot May 13, 2026 14:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Comment thread lib/Listeners/UserEventListener.php Outdated
Comment on lines +37 to +39
$this->logger->info('user added: ' . $event->getUid());
} else {
$this->logger->info('user deleted: ' . $event->getUid());
Comment thread tests/unit/AppInfo/ApplicationTest.php Outdated
Comment on lines 44 to 53
public function testRegisterMethodExists(): void {
// Test that register method registers the InstallationCompletedEvent listener
$this->registrationContext
->expects($this->once())
->expects($this->exactly(3))
->method('registerEventListener')
->with(
InstallationCompletedEvent::class,
InstallationCompletedEventListener::class
);
->willReturnCallback(function (string $event, string $listener): void {
// no assertions needed; just allow the three calls
});

$this->application->register($this->registrationContext);
}
@printminion-co

Copy link
Copy Markdown
Collaborator

@copilot apply changes based on the comments in this thread

fix with autosquashable fixup commits

Copilot AI commented May 13, 2026

Copy link
Copy Markdown

@copilot apply changes based on the comments in this thread

fix with autosquashable fixup commits

Done. Two autosquashable fixup commits added targeting feat(userEventListeners): add UserEventListener and UserStatsJob:

  • 8566958 — switches UserEventListener logging to structured format with capitalized messages and context array ('User added', ['uid' => ...]) to align with app conventions; updates UserEventListenerTest accordingly
  • ecf511e — removes the brittle testRegisterMethodExists that hard-coded the call count; testRegisterListensToUserEvents already validates all expected event/listener pairs

Copilot AI requested a review from printminion-co May 13, 2026 15:02
@printminion-co
printminion-co force-pushed the as/dev/NSW-876-user-event-listener branch from ecf511e to 442ccb4 Compare May 13, 2026 15:06
Listens to UserCreatedEvent and UserDeletedEvent to log synchronous
info entries and schedule a one-shot UserStatsJob that collects the
total user count and logs the NSW-842 stats payload.

Signed-off-by: Arsalan Ul Haq Sohni <arsalan-ul-haq.sohni@strato.de>
@printminion-co
printminion-co force-pushed the as/dev/NSW-876-user-event-listener branch from 442ccb4 to 9434d93 Compare May 13, 2026 15:19
@printminion-co
printminion-co merged commit 9a58e23 into main May 13, 2026
34 checks passed
@printminion-co
printminion-co deleted the as/dev/NSW-876-user-event-listener branch May 13, 2026 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants