11 ms·
I was staring at the example in the readme, and considering some of the features ("replayable"), and it sounds a bit like what a Makefile does. Well, if you had
by shoo 8y ago
I was staring at the example in the readme, and considering some of the features ("replayable"), and it sounds a bit like what a Makefile does. Well, if you had a single event to process, and decided to use the filesystem to store input, intermediate results, and output.
So here's an implementation of the example from the readme using make, and bash, and jq, and a silly python script to implement a timer by modifying a file every X seconds:
~/projects/makething$ cat Makefile
default: d
b: a
curl -o $@ "http://api.coindesk.com/v1/bpi/currentprice.json"
c: b
jq '.bpi.USD.rate_float' $< > $@
d: c
cat $<
cp $< $@
~/projects/makething$ cat timer.py
import sys
import time
def main():
delay = float(sys.argv[1])
fn = sys.argv[2]
while True:
with open(fn, 'w') as f:
f.write(str(time.time()))
time.sleep(delay)
if __name__ == '__main__':
main()
~/projects/makething$ cat go.sh
#! /usr/bin/env bash
python timer.py 2.0 a &
TIMER_PID=$!
function cleanup() {
kill $TIMER_PID
}
trap cleanup EXIT
while true
do
while make -j -q
do
sleep 0.1
done
make -j
done
make decides if things are up-to-date by comparing timestamps of files in the filesystem, so we can emulate a timer that triggers an event every 2 seconds by having a process modify a file every 2 seconds, and rig a rule in our makefile to use that file as an input.
- notduncansmith 8y agoThe interpreter pattern permeates the stack.
- LiveTheDream 8y agoI am a huge fan of using `make` for this sort of ad hoc data pipeline. The workflow is very natural, as you can play around with each step on the command line and then drop it into the makefile once you get it right..better for reproducibility than search up through terminal history to replay individual lines! In your example, I would drop the shell and python scripts and simply run: watch -n 2 -d "touch a && make"
- shoo 8y agothank you for the review and the improvement! much cleaner.
- mistrial9 8y agofrom an abstraction point of view, there is no penalty for wrapping this in some better-for-humans layers above it.. dispatch - with a bit of discipline - is almost costless. <opinion> for decades the *nix culture suffered from "suffer or you arent smart" syndrome, in my opinion. There is nothing wrong with easy, or nice to look at, its just that it is rare to find quality in both the implementation layer (like this) and the interface choices, and then to keep it simple-stupid going forward. I like the simplicity of this, btw</opinion>