I've been watching Laracasts a lot and envy Jeffrey's clean and elegant code. I find though, that in the real world, code always ends up messy.
I can get front-end code looking pretty nice - that's straight forward and easy. But it's the back-end stuff that is causing headaches.
I have numerous apps that do many different things asynchronously, and many are extremely complex working with 3rd-party API's.
For example:
- get email from imap
- parse email
- get data from API
- massage data
- push data to API and get return
- more massaging
- push to another API
- update database etc
The issue is that any one of these steps can fail for any number of reasons, some of which we want to retry for, and some we don't. Eg: network error = retry, Rate limit error = retry later, 404 error = fail entire process, missing data error = try plan b, etc.
So all these beautiful examples of pushing a job to a queue and having a worker deal with it don't work here.
Firstly, I need many workers. The above example is just one "job" and has 8 steps, so realistically I'm looking at 40-80 different worker types per app.
Also, just having regular logs is useless, especially when there's a fatal error (like memory exhaustion). Logs should be per master process so that everything is grouped together (in the above example, per incoming email). In a production system where the logs just fill up with info warn and error lines from non-related processes, the logs are useless.
Also, the individual steps become so tightly coupled because they all need data from previous steps. Not only are they too tightly coupled, but the data they gather becomes unwieldly and huge, causing it's own issues.
Then there's the whole issue of everything being asynchronous and no visibility. It would be nice to be able to review what happened on a per-process basis what's going on (not just per simple job).
Has anyone come across a nice library or at least design pattern to deal with very complex tasks asynchronously in an elegant way?
I've been searching github for hours to no avail.