Hello everyone,
I'm currently facing a challenge in my project. I want to create an event in Laravel that fetches data from an API and logs the process. My goal is to make this process as efficient as possible, so I thought about splitting the responsibilities into two separate listeners.
I have a log table with total_count, processed_count, and status columns, where the status can be 'pending', 'in progress', or 'success'. The first listener is responsible for registering the log and setting the status to 'in progress', followed by fetching the data from the API. I was hoping to pass this data to the second listener, which would then handle inserting the data into the database while updating the processed_count in the log table for each entry processed. Once all the data is processed, the status would be updated to 'success'.
The main motivation behind this approach is to ensure the API is only called once, given that the API URLs will vary but the data structure remains consistent. Additionally, the connection quality of these APIs varies, and the amount of data can be significant. Hence, I want to save resources by avoiding multiple API calls.
This entire process needs to run in the background. Given these requirements, I'm wondering if it's possible to have communication between listeners, or should I consolidate everything into a single listener? My concern is whether using a single listener would be as efficient.
Thank you!