Saturday, August 24, 2019

Hacked Together Like a Dream

Kids just trying to make a living are always the good guys. - Papergirls
On of my fun little side projects, Weather.Next, it sends a weather forecast email if the temperate in the next seven days meets a criteria you configure such as "raining" or "high above 100 degrees." I built it years ago and every once in a while do a security update to a library, but mostly it just runs fine - but then I decided it would be cool if the email told you why the message was triggered.
I thought it would be easy, but uhh, the way I designed the code is that the when the trigger happens the trigger thread makes a web request to pull down the email content from a JSP page. So like, it's in two totally separate execution threads without any good way to pass a large data block. I could theoretically post all the trigger reasons into the page to have it echo out... but that's kind of a gross hack. So instead, I did a different gross hack that I love to hate.
I stored all the trigger reasons into memcache and then pass a triggerId in the URL parameters so the separate page load can read from the memcache and populate. Guess what? It totally worked. Guess what? I can think of all the reasons it won't work (GAE doesn't have a distributed memcache, GAE makes no guarantee anything will even store into memcache). I could solve it, but actually writing into a persistent storage, but why?
Still, now I assume this problem is solved FOREVER. When I do these things, I always think about the many MANY enterprise web apps where engineers did similar work arounds and wonder how the internet even works at all.