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.
Issue
Upon uploading keywords, the scraping will be performed asynchronously via an event listener
https://github.com/tajul-saajan/google-searcher/blob/36a95d4f0ee6216e9fb4abdb15038b12d2f25d54/src/search/listeners/search.listener.ts#L17-L27
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.
Expected
The benefits are: