Pivotal Labs

Main menu

Skip to primary content
Skip to secondary content
  • About
  • Case Studies
  • Team
    • Executives
    • Locations
      • San Francisco (HQ)
      • Boston
      • Boulder
      • Denver
      • London
      • Los Angeles
      • New York
  • Community
    • Blogs
    • Tech Talks
    • Events
  • Careers
    • Lifestyle
    • Principles & Practices
    • Benefits
    • FAQ
    • Apply
  • Contact
    • Press Room
    • Press Releases
    • In The News
    • Press Kit
  • All
  • Labs
  • Standup
  • Tracker

A Stately Resque

George Dean
Thursday, February 7, 2013

Helps

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.

Interestings

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

http://intridea.github.com/stately/

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

Apiary – Public API documentation

http://apiary.io/

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

Events

Thursday: Inaugural Thursday Night Pair Exchange tonight

  • 0 Shares
  • Share on Facebook
  • Share on Twitter

2 Comments

  1. JGeiger says:

    Put the Resque enqueue into an after_commit hook and not an after_save hook.

    February 7, 2013 at 4:36 pm

  2. Jim Kingdon says:

    I second what JGeiger said. If you enqueue the job from after_save, the transaction isn’t committed, and thus isn’t visible to other processes. But after_commit happens after the commit, so the ID is visible.

    February 8, 2013 at 1:11 am

Add New Comment Cancel reply

Your email address will not be published.

George Dean

George Dean
San Francisco

Recent Posts

  • Test automation for iOS and smooth jazz
  • iFrame you frame…
  • Beware RubyMine 5!
Subscribe to George's Feed

Author Topics

agile (4)
chef (1)
git (1)
github (1)
lobot (1)
resque (1)
ios (1)
nyancat (1)
rspec (1)
testing (1)
capybara (1)
homebrew (1)
mediaquery (1)
postgres (1)
sqllite (1)
mysql (1)
rubymine (1)
  • About
  • Case Studies
  • Team
  • Community
  • Careers
  • Contact
  • Labs
  • Events

Contact Us

contact@pivotallabs.com
+1 415-77-PIVOT
TwitterLinkedInFacebook

Pivotal Tracker

Tracker is the award-winning agile project management tool that enables real-time collaboration around a shared, prioritized backlog.
Visit pivotaltracker.com >