Push: Add additional job params for logging

Adds additional job parameters to help diagnose the apparent issue of
jobs being performed twice on Beta.

Bug: T255068
Change-Id: Ib257a24056539487e1110fe286fa4535c3fec94a
This commit is contained in:
Michael Holloway 2020-06-17 15:59:42 -04:00
parent 12090e6b0c
commit a2412732f6
2 changed files with 14 additions and 4 deletions

View file

@ -20,17 +20,27 @@ class PushNotifier {
$attributeManager = EchoAttributeManager::newFromGlobalVars();
$userEnabledEvents = $attributeManager->getUserEnabledEvents( $user, 'push' );
if ( in_array( $event->getType(), $userEnabledEvents ) ) {
JobQueueGroup::singleton()->push( self::createJobForUser( $user ) );
JobQueueGroup::singleton()->push( self::createJob( $user, $event ) );
}
}
/**
* @param User $user
* @param EchoEvent|null $event
* @return NotificationRequestJob
*/
private static function createJobForUser( User $user ): NotificationRequestJob {
private static function createJob( User $user, EchoEvent $event = null ):
NotificationRequestJob {
$centralId = CentralIdLookup::factory()->centralIdFromLocalUser( $user );
$params = [ 'centralId' => $centralId ];
// below params are only needed for debug logging (T255068)
if ( $event !== null ) {
$params['eventId'] = $event->getId();
$params['eventType'] = $event->getType();
if ( $event->getAgent() !== null ) {
$params['agent'] = $event->getAgent()->getId();
}
}
return new NotificationRequestJob( 'EchoPushNotificationRequest', $params );
}

View file

@ -7,11 +7,11 @@ use Wikimedia\TestingAccessWrapper;
/** @covers \EchoPush\PushNotifier */
class PushNotifierTest extends MediaWikiIntegrationTestCase {
public function testCreateJobForUser(): void {
public function testCreateJob(): void {
$notifier = TestingAccessWrapper::newFromClass( PushNotifier::class );
$user = $this->getTestUser()->getUser();
$centralId = CentralIdLookup::factory()->centralIdFromLocalUser( $user );
$job = $notifier->createJobForUser( $user );
$job = $notifier->createJob( $user );
$this->assertInstanceOf( NotificationRequestJob::class, $job );
$this->assertSame( 'EchoPushNotificationRequest', $job->getType() );
$this->assertSame( $centralId, $job->getParams()['centralId'] );