Skip to content

Instantly share code, notes, and snippets.

@groundwater
Created July 25, 2013 16:52
Show Gist options
  • Save groundwater/6081646 to your computer and use it in GitHub Desktop.
Save groundwater/6081646 to your computer and use it in GitHub Desktop.

I very often automate tasks using bash, a Makefile, or some other means. By far the best advice I can give anyone is to make your tasks idempotent. Let me say that again:

make your tasks idempotent

Having said that, it can be difficult when there are sub-tasks that should only be run once. Here is my small life-hack around that:

  1. check for the existence of a dot-file, e.g. .db-create-tables
  2. if the dot-file does not exist, run the task and pipe the output to .db-create-tables.tmp
  3. upon success, and only on success, mv .db-create-tables.tmp .db.create-tables

This has the added benefit of being able to see the output of your various tasks, while also leaving a definitive marker of their success.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment