Creating self starting worker machines for fun and profit – Avi Tzurel

I wrote a blog post in my other personal blog about how to create a machine that will manage it’s own lifecycle.

I work a lot with background workers, and I constantly need a better way to manage my Resque worker machines, so I wrote a post about how I did it.

I booted up over 50 servers with about 600 Resque workers using this method, and all with a click of a button in the UI.

Worth your time to read it if you are using Resque/Sidekiq and you need to add workers on rush-times of your site or something.

Creating self starting worker machines for fun and profit – Avi Tzurel.

Lessons Learned: The First Six Months of Running a Software Consultancy

If you are running a consultancy business, or even thinking about it, this post is a must read for you.

The comments are sometimes even more interesting then the post itself, some very interesting discussions were ignited by this post.

Lessons Learned: The First Six Months of Running a Software Consultancy.

Where are my engines?

Right now, I am working on an engine for the Gogobot application.

As part of my work on the engine, I am working with the Mongoid gem and the Fabrication gem, both great gems b.t.w.

The problem with Fabrication is that it wasn’t really adapted to working with Engines and it was relying a lot on Rails.root for where to locate the fabricator files.

Since in an engine, the application is located in spec/dummy I needed a better way locate the fabricators.

ok… so far the story of how I got to even writing this post.

To solve my problem I needed to grab all of the engines that are included inside the Rails application.

Turns out, there’s a real easy way to do it.

You can look at my solution including this line in the pull request I have open for Fabrication here: https://github.com/paulelliott/fabrication/pull/114

undefined method `relation’ for nil:NilClass on Heroku

I host almost 100% of my open source projects on Heroku, it’s amazing how easy it is to setup and how “out-of-your-way” they are.

Today, while working on one of my open source project I encountered this error:

It was right after I deployed and migrated the database.

After about 5 minutes of head scratching I came across an answer on stackoverflow saying you have to restart your app after a migration for it to pick up on schema changes.

Had a DAH! moment there :-)

The simplest Enum you will ever find for your ActiveRecord models

I have been using a really useful snippet for a while now.

While dropping it today into a project I realized just how powerful it is:

  1. it’s a drop-in and will work on any project
  2. it’s database agnostic
  3. it’s dead simple
  4. it’s not sensitive to enum changes
  5. and more and more

Just as an into, an enum is a way to have string represented as integers in your database.

Why?

Because integers are much faster to index and query (at least on mysql).

MySQL has an enum solution but ActiveRecord can’t really use it without some nasty hacking and it’s really messy when you want to add another param.

Enough Said, here’s the snippet

This gives you the ability to work with the Account model like so:

As you can see, it’s being persisted into the database as an integer, but you work with symbols/strings which is much nicer and cleaner.

Showing the git commit SHA that is currently deployed

I cannot count how many times I (or others) have asked the following question:

What is the difference between master and the production version?

We deploy about 3-5 times a day and we merge code about twice as much into master (some days, even more then that).

We deploy to servers with Capistrano, Capistrano has a very useful feature to write a REVISION file to the root of the project, this file contains a single line with the commit sha.

So, I thought I might set up a controller that will read this file and display it when I want.

So, I spec’d it out:

And this is the controller code:

 

A Baseline for Front-End Developers – Adventures in JavaScript Development

I stumbled upon this terrific post on Twitter.

This post goes into details (very deeply) about what it takes to be a Front End developer these days.

The amount of things and tools you need to know are overwhelming.

I recommend taking the time and reading it, it’s long, but worth every second you put into it.

A Baseline for Front-End Developers – Adventures in JavaScript Development.

Find the source location of a method in your project

Ruby/Rails project sometimes make it hard to find the source location of a method.

Sometimes, Duck typing, meta-programming and just plain bad design make it really hard to find where a method was defined and how.

Luckily, there’s an easy way around this.

So, here’s an example.

A few moments ago, I came across this line:

First thing I did (obviously) was going to the user class and searching for this method. Obvious enough (or this post would not exist) I could not find it.

I immediately realized it’s being defined by some cache mechanism we have.

So, I opened up a console and typed this:

And it returned

So, the method IS defined on the user somewhere, you can see exactly where like so:

This will give you an exact location where the method is defined, I found this line:

This trick saves me time, hope it will save you some browsing around helplessly, especially in bigger non-single-dev projects

EDIT: 12 APR 2012 10:51PM
I posted a link to this post in the dev chat room on Campfire.

Steve, had an awesome comment:

Campfire conversation

We are using Octopus gem in our application (Gogobot), this gem is used to connect to databases with master/slave architecture.

Just as a general warning, you may get some results like that. but if you follow the source location, it’s usually a very good hint of where the method is actually defined and in any case, I think those Proxy situations are rare.

Awesome comment nonetheless, so I though I might update the post with it.

EDIT: 12 APR 2012 11:01PM

Jonathan Jackson replied to me on twitter, he said, that if you are using Pry (which you should) you can actually do it even better.

if you open up the console and do:

This will open up the default editor (Vim in my case) in the exact location where the method is defined and you are able to edit it in place.

Another awesome comment that was worth a post update :-)

Testing the Notifier class with Rspec

Today, I needed to spec the Notifier (mailer) class in a Rails project.

I don’t mean to spec the view, I just needed to test if the Notifier class method was being called with some params.

For example, I had this user story

As a User
When I am an owner of an issue
And the issue status changes
I want to get an email

So, all I had to to in my spec, is to test if the Notifier class was being called, I am testing the view in the notifier_spec, so no need to test it twice.

So, I wrote this code.

When I ran the spec, I was surprised to see this error:

After scratching my head for a while, I realized that since I used mocks and expectations for the Notifier class, the underlying code was never called, so it wasn’t returning the Mail::Message class.

I fixed it by doing this:

And now I have a happy spec file, that is only testing the messages between the classes, which is what I wanted to do in the first place.

With GOV.UK, British government redefines the online government platform – O’Reilly Radar

Reading this article made me realize there’s hope in making government sites better.

The state of the government sites in Israel for example is shameful, all written in .Net, no standards and no cross-platform consideration.

It’s a very good read.

Why create an open source stack? “Why not?” asked Bracken. “It’s a government platform, and as such it belongs to us all and we want people to contribute and share in its development.”

via With GOV.UK, British government redefines the online government platform – O’Reilly Radar.