Added logging to collections event handlers

This will help us with debugging issues we're seeing with large sites
This commit is contained in:
Fabien "egg" O'Carroll 2023-09-08 11:31:12 +07:00 committed by Fabien 'egg' O'Carroll
parent fc5f139d39
commit c6f908d31d

View File

@ -175,12 +175,20 @@ export class CollectionsService {
subscribeToEvents() {
this.DomainEvents.subscribe(PostDeletedEvent, async (event: PostDeletedEvent) => {
logging.info(`PostDeletedEvent received, removing post ${event.id} from all collections`);
try {
await this.removePostFromAllCollections(event.id);
} catch (err) {
logging.error({err});
}
});
this.DomainEvents.subscribe(PostAddedEvent, async (event: PostAddedEvent) => {
logging.info(`PostAddedEvent received, adding post ${event.data.id} to matching collections`);
try {
await this.addPostToMatchingCollections(event.data);
} catch (err) {
logging.error({err});
}
});
this.DomainEvents.subscribe(PostEditedEvent, async (event: PostEditedEvent) => {
@ -189,37 +197,65 @@ export class CollectionsService {
}
logging.info(`PostEditedEvent received, updating post ${event.data.id} in matching collections`);
try {
await this.updatePostInMatchingCollections(event.data);
} catch (err) {
logging.error({err});
}
});
this.DomainEvents.subscribe(PostsBulkDestroyedEvent, async (event: PostsBulkDestroyedEvent) => {
logging.info(`BulkDestroyEvent received, removing posts ${event.data} from all collections`);
try {
await this.removePostsFromAllCollections(event.data);
} catch (err) {
logging.error({err});
}
});
this.DomainEvents.subscribe(PostsBulkUnpublishedEvent, async (event: PostsBulkUnpublishedEvent) => {
logging.info(`PostsBulkUnpublishedEvent received, updating collection posts ${event.data}`);
try {
await this.updateUnpublishedPosts(event.data);
} catch (err) {
logging.error({err});
}
});
this.DomainEvents.subscribe(PostsBulkFeaturedEvent, async (event: PostsBulkFeaturedEvent) => {
logging.info(`PostsBulkFeaturedEvent received, updating collection posts ${event.data}`);
try {
await this.updateFeaturedPosts(event.data);
} catch (err) {
logging.error({err});
}
});
this.DomainEvents.subscribe(PostsBulkUnfeaturedEvent, async (event: PostsBulkUnfeaturedEvent) => {
logging.info(`PostsBulkUnfeaturedEvent received, updating collection posts ${event.data}`);
try {
await this.updateFeaturedPosts(event.data);
} catch (err) {
logging.error({err});
}
});
this.DomainEvents.subscribe(TagDeletedEvent, async (event: TagDeletedEvent) => {
logging.info(`TagDeletedEvent received for ${event.data.id}, updating all collections`);
try {
await this.updateAllAutomaticCollections();
} catch (err) {
logging.error({err});
}
});
this.DomainEvents.subscribe(PostsBulkAddTagsEvent, async (event: PostsBulkAddTagsEvent) => {
logging.info(`PostsBulkAddTagsEvent received for ${event.data}, updating all collections`);
try {
await this.updateAllAutomaticCollections();
} catch (err) {
logging.error({err});
}
});
}