Scheduling Crowd-Sourced Entropy with Webhooks
Fair Dice Roll meets Dead Man's Snitch
I love writing gems. Lately, I've been particularly interested in tackling the big, important problems in math, like how can a computer generate a truly random number. I took this challenge head-on when I developed the fair\_dice\_roll gem.
Fair Dice Roll is a funny little gem that asks the community to contribute their own "random" numbers. The inspiration came from my most trusted source of mathematical theory on the internet, XKCD:
However, mathematical perfection comes at a cost. Fair Dice Roll has a weakness. Its randomness is crowd-sourced so it depends entirely on continued contribution from the open source community.
The Challenge
According to my calculations, a new roll of the die every month should produce adequate entropy. The hard part is ensuring that a new roll occurs each and every month. Enter: Dead Man's Snitch.
The Solution
Dead Man's Snitch is a periodic task monitoring service that alerts you when your task doesn't run, which is perfect for Fair Dice Roll.
Step 1: Register
Registering at Dead Man's Snitch gives you one free "snitch," letting you monitor one task at no cost. I named my free snitch "Fair Dice Roll" and configured it to expect monthly check-ins.
Step 2: Install a Webhook
When you create your first snitch, you get a unique URL that looks like this:
https://nosnch.in/c2354d53d2
To check in to your snitch, you just request that URL. Checking in lets Dead Man's Snitch know that your task is running as expected. One great way to check in is to use webhooks, also known as HTTP callbacks.
With Fair Dice Roll, we care about the process of rolling a die, updating the code, and releasing a new version. Fortunately, RubyGems.org gives you the ability to install webhooks that will fire when new versions of specific gems are released. You can install a RubyGems webhook from the command line using the "gemcutter" gem:
$ gem install gemcutter
$ gem webhook fair_dice_roll --add https://nosnch.in/c2354d53d2
Step 3: Carry On
Now, whenever a new version of Fair Dice Roll is released, Dead Man's Snitch will automatically be notified. If a month ever passes without a new version being released, Dead Man's Snitch will send an email to remind me.
What Else?
Yes, Fair Dice Roll is sort of a silly example, although I do actually have this exact setup in place. But Dead Man's Snitch works great for any service that provides webhooks. Here are a few other ideas:
- Use Slack's outgoing webhooks to practice saying "thank you" to someone everyday.
- Use Square's webhooks to remind you to collect rent from your tenants.
- Use GitHub's webhooks to encourage daily pull request review.
- Use Heroku deploy hooks to remind your team to deploy to production on a weekly basis.
What other interesting integrations can you dream up using Dead Man's Snitch and webhooks?
Comments