A Stately Resque

February 7, 2013 George Dean


ActiveRecord save race condition in Resque

We have a Rails app that is saving a new ActiveRecord object, and then immediately afterwards, enqueueing a Resque job that looks up that record by its ID. Sometimes, the lookup inside the resque job fails – it claims no such row with that ID exists.

If we put the lookup into a loop that catches that exception and retries the exact same lookup, it always eventually succeeds, usually after 1-2 seconds.

The ID exists on the ActiveRecord object before the job is enqueued, which (I think) means that the save transaction has completed. But the resque job is using a different database connection, so maybe there's some weird caching going on? But here Google has failed us.

Any ideas? We could leave it in a loop that catches the exception, sleeps 1 second, and retries, but: ugh.

Some ideas from the audience:
There is a connection object that can be queried about transaction states.
Wait for transaction count increment/decrement?
Could be a problem with the way that sqlite fakes nested transactions.

Best practices for individual users on GitHub

Usually we have a single GitHub account for a project that contains a key for each of the machines being used on a project. On our project we want to use a separate account for each person on the project. Is there a way to do this without a lot of trouble shuffling SSH keys around?

Pivotal Git Scripts may have some tools for this.
You can also use HTTPS URLs and enter username/password on each commit.


Lobot – Now with per-project chef recipes

If you need to write your own chef recipes to install your project's dependencies, you can add a cookbooks directory to the root of your project. Make sure to delete the cookbook_paths section from your lobot.yml (to use the default values), or add ./chef/project-cookbooks to the cookbook_paths section.

So, to have a bacon recipe, you should have cookbooks/pork/recipes/bacon.rb file in your repository.

Stately – A font of the US states


For all those times you need a vector representation of the USA and to color the states separately.

Apiary – Public API documentation


Takes a well formed file and generates really usable REST API documentation. Integrates with Github for collaboration


Thursday: Inaugural Thursday Night Pair Exchange tonight

About the Author


Visual.ly Predicts 2013’s Hot Data Visualization Trends
Visual.ly Predicts 2013’s Hot Data Visualization Trends

Last weekend, data visualization social network visual.ly hosted a Meetup in San Francisco, offering a glim...

Heroic Feats of Data Scientists Doing Good
Heroic Feats of Data Scientists Doing Good

These heroic data divers serve a critical need, devoting nights and weekends to munging messy XML files, de...

SpringOne 2021

Register Now