Simple Process Coordination with Tellmewhen
I subscribe to the Unix is my IDE philosophy, mixing and matching the gnu tools, Leiningen, and lots of other tools. I frequently go to bash, Ruby and Rake in order to tie or glue many of those tools together in ad-hoc combinations to get tasks done or create small automations.
I often want is to be notified when a task completes, or to trigger an action after another task completes. bash
has some features that allow you to background a process and await the completion of that process, like wait, but wait
doesn’t fit all of my use cases.
I recently checked out Phil Hagelberg’s Slamhound dependency analysis and cleanup tool for Clojure to troubleshoot an issue I was having. Not knowing much about Leiningen plug-ins and how to effectively do interactive development with them, I started with the classical development cycle: edit the code (add print statements, make some tweaks); compile and install the code; and run the plug-in.
The disconnect for me was that my test case was in another project wasn’t part of Slamhound itself, so I was doing the build and install of Slamhound then switching to another tab and executing my test.
I created Tellmewhen for exactly this kind of use case. You can used it to implement a lightweight form of IPC using basic bash commands and files.
I stacked together the execution of Leiningen to build the software and then touch a trigger file in my $HOME
directory that my other process could then wait on:
user@host ~/projects/slamhound $ lein deps && lein install && touch ~/x
Meanwhile…in another terminal, I used tellmewhen
to await the update to the file ~/x
and then execute my test:
user@host ~/personal/projects/impresario $ tellmewhen -m ~/x ; lein deps && lein slamhound src/impresario/core.clj
I could run this first (or just after I started the slamhound build) and it would (almost) immediately kick off when the slamhound install successfully completes.
This was a lightweight way for me to script and coordinate between these activities. Automating it one step further was as easy as wrapping a while loop around the test case:
user@host ~/personal/projects/impresario $ while :; do \ tellmewhen -m ~/x ; \ lein deps && lein slamhound src/impresario/core.clj; \ done
Then my test case will execute, and await another build + install of slamhound from the other terminal.
The Unix philosophy focuses on modularity – small, re-usable, composable components. I see parallels to the composability of Functional Programming constructs as well. tellmewhen
is becoming a tool I’m using more frequently, mixing it into my other tool-set. I hope you find it useful too.