|
Hey this is Isaac, This week I was fixing some basic and classic async problems: a "processing" pill that never updated to "complete." Blech. The goal is to prevent long-running tasks from freezing the user interface. If something takes a second, it’s fine to expect the user to stay on the page until it completes. But if it takes 5 minutes? Users will want to be able to do other things while it’s processing. So we have background tasks that run independently of the UI the user sees. But the user will still expect to see updates and watch the job though! For a project I am working on, Devrelifier, the updates were not working for this processing pipeline:
For a 90-minute video, that can take quite a while! I needed a clean and simple way to update the UI after a background job finished.. The Build: Choosing Simplicity Over InfrastructureThe user clicks “Generate” to start background jobs that generate content. It can take a while, especially if it’s processing a long video, and the user may want to navigate to other pages or wait and watch the job in the UI until it completes. Once the background job is running, there are two main options to deliver updates to the UI:
I chose simplicity of logic. A 1-second delay in the UI updating for a long-running background task is inconsequential for what I was doing. For many things, like a chat application, the real-time updates SSE gives are really important. SSE requires managing active connections, which is typically implemented using something like the HTMX SSE extension. The extension allows you to keep code very light, but I think regular HTTP requests with fewer dependencies make for easier testing, debugging, and maintenance. The Learn: The "Self-Polling Pill"Here’s the pattern I used. It's a self-contained component that polls every second and then stops itself. Here’s how it works:
The Refactor: From 4x Duplication to 1 ConfigThe self-polling pill worked quite well, but after a while I realized that I had almost the same logic in 4 places! blog_actions, newsletter_actions, twitter_actions, and linkedin_actions. The old way: Each content type had its own duplicated logic for the "Generate" button and the completion button ("Edit" vs. "View"). This logic was mirrored in the main view and in the status endpoint. It was a headache-in-waiting. The new way: I refactored all of it into a single, config-driven helper: build_content_actions(project, task_type). This function uses a small config dictionary that maps a task_type (like "blog") to:
This simple refactor replaced about 100 lines of duplicated code. More importantly, adding a new content type is much easier (and I plan on adding many more!) Until next week, Isaac |
Hi! I'm Isaac Flath, a Tech Generalist passionate about creating beautiful, functional, useful things. While this often means AI it often means Web App Development, Dev Ops, System Administration, and other things. AI is only a component (sometimes a relatively small one) of a successful AI application.
Hey this is Isaac, This week has been about closing loops. I'm releasing the DevRelifier (product for helping share and promote tech stuff), which means dealing with the unsexy parts of software development: tax setup and final testing. It’s less about coding creative features and more about ensuring the business actually works without breaking the law or the user experience. If you want to try the product, reply to this email for more info and free credits. The Build: The Unsexy Last Mile...
Hey this is Isaac, I met with some dear friends, Danny and Audrey Roy Greenfeld, in Baltimore for a mini-sprint on the air web-dev framework. Walking around a science museum while brainstorming and cafe-hopping while hacking together was a blast. During the sprint I created a new testing example (unit, integration, and end-to-end playwright tests) and began extracting features from private codebases into small, public libraries. I also learned that a late evening espresso martini is not the...
Hey this is Isaac, Welcome to my new weekly newsletter. Each week, we explore one build, one lesson, and one refactor. Only practical ideas to help you build better. This week I jumped from untangling a messy Stripe integration to light creativity generating an AI promo video. The mental whiplash is real. Let's start with the AI Promo Video. The Build: Directing an AI to Make a Promo Video I created a 74-second promo video draft in about 30 minutes. AI wrote the code, but I was the creative...