Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Chore] Brittle asynchronous processing of keywords #8

Open
olivierobert opened this issue Nov 28, 2023 · 0 comments · Fixed by #14
Open

[Chore] Brittle asynchronous processing of keywords #8

olivierobert opened this issue Nov 28, 2023 · 0 comments · Fixed by #14
Assignees

Comments

@olivierobert
Copy link

Issue

Upon uploading keywords, the scraping will be performed asynchronously via an event listener

@OnEvent('file.uploaded', { async: true })
async handleOrderCreatedEvent(payload: FileUploadedEvent) {
for (const { keyword } of payload.rowObject) {
const result = await this.searcher.search(keyword);
await this.entityManager.save(SearchStat, {
...result,
keyword,
});
console.log('saved to db');
}
}

All keywords are processed in a loop. If any error occurs in the loop, the latter will stop, and all remaining keywords will not be scraped and will not even have been saved to the database. A queue (supported by Nest.JS, see: https://docs.nestjs.com/techniques/queues) would be a better fit in this case.

Warning

Using the observer pattern can be beneficial when there is more than one subscriber/consumer. Since the event is consumed in the same module as it is emitted, it creates indirection unnecessarily.

Expected

  • Keywords should be stored in the database with a flag to track the scraping status as soon as they are uploaded
  • A distinct background job to scrap the Google page for each keyword is then scheduled.

The benefits are:

  • Fast CSV upload request
  • The scraping of each keyword is isolated, i.e., one could error while others could be successful.
@tajul-saajan tajul-saajan self-assigned this Nov 29, 2023
@tajul-saajan tajul-saajan linked a pull request Nov 29, 2023 that will close this issue
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 a pull request may close this issue.

2 participants