<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>JonHoman.com</title>
	<atom:link href="http://blog.jonhoman.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.jonhoman.com</link>
	<description>Walking the Long Road</description>
	<lastBuildDate>Tue, 26 Apr 2011 22:30:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Simple Way to Autoscale Heroku Workers</title>
		<link>http://blog.jonhoman.com/simple-way-to-autoscale-heroku-workers/</link>
		<comments>http://blog.jonhoman.com/simple-way-to-autoscale-heroku-workers/#comments</comments>
		<pubDate>Fri, 08 Apr 2011 02:16:13 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[apprenticeship]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[heroku]]></category>
		<category><![CDATA[resque]]></category>

		<guid isPermaLink="false">http://blog.jonhoman.com/?p=391</guid>
		<description><![CDATA[Yesterday I had a revelation: the Heroku gem can start and stop workers. For the last few months, I&#8217;ve been manually kicking off a rake task to start a worker to catch up on Resque queues. Now, my cron task &#8230; <a href="http://blog.jonhoman.com/simple-way-to-autoscale-heroku-workers/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Yesterday I had a revelation: the Heroku gem can start and stop workers.</p>
<p>For the last few months, I&#8217;ve been manually kicking off a rake task to start a worker to catch up on Resque queues.</p>
<p><img class="alignleft" title="Facepalm" src="http://picardfacepalm.com/picard-facepalm-hotlink.jpg" alt="Facepalm" width="700" height="528" /></p>
<p>Now, my cron task starts up a Heroku worker, queues up the updates that workers need to do, and shutdowns the worker once the queues are empty.</p>
<p>This works great for me since <a href="http://life-streams.com">my app</a> has regular processes to run, but generally empty queues so having a worker running all the time isn&#8217;t very cost effective.</p>
<p>Here&#8217;s the basics:</p>
<pre>require 'heroku'

desc "This task is called by the Heroku cron add-on"
task :cron =&gt; :environment do
  client = Heroku::Client.new(heroku_user, heroku_pass)
  # start a worker
  client.set_workers(heroku_app, 1)

  # Do stuff
  .....

  sleep 10 # wait for worker to start up

  if Resque.working.empty? # returns list of workers that are working
    # stop the worker
    client.set_workers(heroku_app, 0)
  else
    # wait for jobs to finish
    sleep 5
  end
end</pre>
<p>This has pretty worked well for me so far. No longer do I need to manually start a worker. And I also am keeping my costs low by running the worker only when they are jobs to be processed.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jonhoman.com/simple-way-to-autoscale-heroku-workers/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Getting Started with webmock and VCR</title>
		<link>http://blog.jonhoman.com/getting-started-with-webmock-and-vcr/</link>
		<comments>http://blog.jonhoman.com/getting-started-with-webmock-and-vcr/#comments</comments>
		<pubDate>Sun, 20 Mar 2011 21:36:45 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[apprenticeship]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[vcr]]></category>
		<category><![CDATA[webmock]]></category>

		<guid isPermaLink="false">http://blog.jonhoman.com/?p=361</guid>
		<description><![CDATA[Last time, I introduced what WebMock and VCR can do for you. Now, let&#8217;s see what we need to do to get them set up in a Rails 3 application in our RSpec and Cucumber tests. Note, for this post, &#8230; <a href="http://blog.jonhoman.com/getting-started-with-webmock-and-vcr/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.jonhoman.com/faking-http-requests-with-webmock-and-vcr/">Last time</a>, I introduced what <a href="https://github.com/bblimke/webmock">WebMock</a> and <a href="https://github.com/myronmarston/vcr">VCR</a> can do for you. Now, let&#8217;s see what we need to do to get them set up in a Rails 3 application in our RSpec and Cucumber tests.</p>
<p>Note, for this post, we won&#8217;t cover using WebMock separately from VCR, but you can see how I use WebMock without VCR&#8217;s recorded responses to test the Twitter OAuth handshake in this <a href="https://github.com/jonhoman/lifestreams/commit/5a1adfbfcc97dcebbd6d3bdfa8577ac9e5f7cbae">commit</a>.</p>
<p>Okay, let&#8217;s get started. The first thing you will need to do is add WebMock and VCR to your project&#8217;s Gemfile.</p>
<pre class="ruby">gem 'webmock', '1.6.2'
gem 'vcr', '1.6.0'</pre>
<p>Now, we need to make sure our tests load up the WebMock library. Assuming you are using RSpec and Cucumber, edit spec/spec_helper.rb and features/support/env.rb to require WebMock.</p>
<pre class="ruby"># spec/spec_helper.rb
require 'webmock/rspec'</pre>
<pre class="ruby"># features/support/env.rb
require 'webmock/cucumber'</pre>
<p>WebMock also supports Test::Unit. For information on configuration, take a look at <a href="https://github.com/bblimke/webmock">webmock&#8217;s documentation</a>.</p>
<p>We also need to configure vcr. Edit spec/spec_helper.rb.</p>
<pre class="ruby">require 'vcr'</pre>
<p>And inside of the RSpec.configure block:</p>
<pre class="ruby"># Gives you 'use_vcr_cassette' as a macro
config.extend VCR::RSpec::Macros</pre>
<p>Now create a new file in spec/support called vcr.rb and add the following:</p>
<pre class="ruby">require 'vcr'

VCR.config do |c|
  c.cassette_library_dir = 'fixtures/cassette_library'
  c.stub_with :webmock
  c.ignore_localhost = true
  c.default_cassette_options = { :record =&gt; :none }
end</pre>
<p>Let&#8217;s quickly go over the configuration options:</p>
<ul>
<li><code>cassette_library_dir</code> sets up the directory where your recorded responses will be stored.</li>
<li><code>stub_with</code> tells VCR which library to use to fake the HTTP requests.</li>
<li><code>ignore_localhost</code> tells VCR whether or not to allow local requests.</li>
<li><code>default_cassette_options</code> set up defaults for recording, re-record, etc.</li>
</ul>
<p>Now to use VCR in our specs. First, we need to set up the cassette we want VCR to use. I do this this at the beginning a spec file, generally right after the initial describe.</p>
<pre class="ruby">describe Feed do
  use_vcr_cassette "feed", :record =&gt; :new_episodes

  ....

end</pre>
<p>The use_vcr_cassette declaration tells VCR to record the responses of any HTTP requests in the cassette we give, in this case feed.</p>
<p>And now let&#8217;s get VCR in our cukes.</p>
<pre class="ruby">When /^I make an external call$/ do
  VCR.use_cassette("feed", :record =&gt; :new_episodes) do
    When 'I press "Create Feed"'
  end
end</pre>
<p>Because I am using a web step provided by <a href="https://github.com/jnicklas/capybara">capybara</a>, I needed to create a new step definition that just delegated to the original step but wrapped the original step in the use_cassette block.</p>
<p>Other times, I was already using a custom step, so I simply added the use_cassette block to the step definition.</p>
<pre>Given /^I have a feed I want to edit$/ do
  VCR.use_cassette("feed", :record =&gt; :new_episodes) do
    @feed = Factory :feed
  end
end</pre>
<p>VCR provides a Cucumber macro similar to the RSpec macro above, but I wasn&#8217;t able to get it working quickly and haven&#8217;t gone back to it. I know a coworker was able to use it correctly, so it&#8217;s definitely an issue of user error and not an issue with VCR.</p>
<p>Another nice feature in VCR is the ability to re-record the responses. This stops the recorded responses from getting stale over time and automatically does this on a defined interval.</p>
<p>You can set this up in the vcr.rb we created earlier. The change is bolded.</p>
<pre>require 'vcr'

VCR.config do |c|
  c.cassette_library_dir = 'fixtures/cassette_library'
  c.stub_with :webmock
  c.ignore_localhost = true
  c.default_cassette_options = { :record =&gt; :none,
                                 <strong>:re_record_interval =&gt; 7.days</strong> }
end</pre>
<p>As you can see, we are adding re_record_interval to the default options. I set this interval to be 7 days since I don&#8217;t want the real requests to be run very often. And seven days is often enough that I will be able to respond quickly to changing responses.</p>
<p>Check out the <a href="https://github.com/jonhoman/lifestreams/tree/webmock">webmock</a> branch of lifeStreams on Github to see how I add WebMock and VCR. The first relevant commit is &#8220;<a href="https://github.com/jonhoman/lifestreams/commit/0e607a3b7060c4bed2ba992034d01cd20e94ce94">start with webmock</a>&#8221;</p>
<p>Using WebMock and VCR has made testing the 3rd-party APIs I&#8217;m using in lifeStreams much easier and is a great alternative to hand-rolling stubs for the API responses. Take a look at their projects the next time you need to test external resources.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jonhoman.com/getting-started-with-webmock-and-vcr/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Faking HTTP requests with WebMock and VCR</title>
		<link>http://blog.jonhoman.com/faking-http-requests-with-webmock-and-vcr/</link>
		<comments>http://blog.jonhoman.com/faking-http-requests-with-webmock-and-vcr/#comments</comments>
		<pubDate>Tue, 01 Mar 2011 15:00:01 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[apprenticeship]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[vcr]]></category>
		<category><![CDATA[webmock]]></category>

		<guid isPermaLink="false">http://blog.jonhoman.com/?p=349</guid>
		<description><![CDATA[My pet project, lifeStreams, has a lot of interaction with external websites like Twitter and user&#8217;s blogs. Since the majority of the interesting bits of the website have to do with these external sites, I needed to find a good &#8230; <a href="http://blog.jonhoman.com/faking-http-requests-with-webmock-and-vcr/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>My pet project, <a href="http://life-streams.com">lifeStreams</a>, has a lot of interaction with external websites like Twitter and user&#8217;s blogs. Since the majority of the interesting bits of the website have to do with these external sites, I needed to find a good way to write automated tests around these external calls.</p>
<p>I heard of <a href="https://github.com/bblimke/webmock">WebMock</a> through some chatter on Twitter and came across <a href="https://github.com/myronmarston/vcr">VCR</a> when reading WebMock&#8217;s README. WebMock is a library that allows you to fake HTTP requests to external websites and APIs. That&#8217;s basically what I needed: a way to fake an HTTP request to update a status a Twitter, for example, in my automated tests. So how did VCR come into play?</p>
<p>VCR records the initial HTTP response and replays that response for subsequent requests. So, once you have VCR setup, your tests will make one real request and then the recorded requests are used by WebMock. One nice option is re-recording these web requests on an interval to ensure the recorded responses don&#8217;t get stale.</p>
<p>Using this setup, you&#8217;re tests can speed up quite a bit. My <a href="http://twitter.com/jonhoman/status/37743388228853760">results</a> showed a marked improvement. This time difference was mainly due to the fact that my application makes a request to a user&#8217;s blog for their RSS/Atom feed whenever a feed is created. So, my tests were spending a lot of time making requests to figure out the feed urls. Once I got WebMock and VCR in place, I could stand running my tests again.</p>
<p>Soon I will have another post outlining how to get started with WebMock and VCR. In the mean time, you can view the <a href="https://github.com/jonhoman/lifestreams/commits/webmock">commits</a> to my project as I started using WebMock and VCR. The first WebMock related commit is &#8220;start with webmock&#8221;.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jonhoman.com/faking-http-requests-with-webmock-and-vcr/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The Secret of Developing Software</title>
		<link>http://blog.jonhoman.com/the-secret-of-developing-software/</link>
		<comments>http://blog.jonhoman.com/the-secret-of-developing-software/#comments</comments>
		<pubDate>Sun, 30 Jan 2011 20:33:36 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[apprenticeship]]></category>
		<category><![CDATA[dev]]></category>

		<guid isPermaLink="false">http://blog.jonhoman.com/?p=333</guid>
		<description><![CDATA[For as long as I can remember I have been a big basketball fan. Some of my earliest memories include ripping open a package of basketball cards to see what new players I would learn about, shooting hoops with my &#8230; <a href="http://blog.jonhoman.com/the-secret-of-developing-software/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>For as long as I can remember I have been a big basketball fan. Some of my earliest memories include ripping open a package of basketball cards to see what new players I would learn about, shooting hoops with my brother on a Fisher-Price basketball hoop, watching MJ play on TV, and play in the YMCA basketball leagues from an early age. I even learned to read by looking at basketball cards and putting the player names to their faces.</p>
<p>So this Christmas I was pretty excited when my brother got me Bill Simmons&#8217; <a href="http://www.amazon.com/Book-Basketball-NBA-According-Sports/dp/0345520106">The Book of Basketball</a>. Simmons takes a look at the greatest players in the NBA and what made them great. One of the first topics he covers is The Secret:</p>
<blockquote><p>The secret of basketball is that it&#8217;s not about basketball.</p></blockquote>
<p>Simmons in an <a href="http://sports.espn.go.com/nba/news/story?id=4746227">article</a> on ESPN.com describe The Secret:</p>
<blockquote><p>The Secret, in a nutshell: Teams only win titles when their best players forget about statistics, sublimate their own games for the greater good and put their egos on hold.</p></blockquote>
<p>In other words, basketball is more about people than it is about basketball.</p>
<p>Early last week, a coworker said something to the effect that the most important things we do aren&#8217;t technical. Then last week while eating lunch, I put his statement together with The Secret and had a crazy thought:</p>
<p>What if the secret of software development is that it&#8217;s not about software development? Could software development be more about people than software development?</p>
<p>In basketball <strong>teamwork, chemistry, will to win, sacrifice</strong> are all more important than <strong>basketball skills and individual statistics</strong>. Could the same be true of software development?</p>
<ul>
<li><strong>Teamwork</strong>: Do your developers &#8220;play well together&#8221;? This is especially important in pairing organizations.</li>
<li><strong>Chemistry</strong>: Similar to teamwork, but how well does your team get along in general? Do you have any &#8220;team cancers&#8221; that cause unneeded conflict rather than help the team?</li>
<li><strong>Will to Win</strong>: Here, will to deliver. Does your team truly care about delivering software that has value to the stakeholders?</li>
<li><strong>Sacrifice</strong>: Are your team members willing to swallow their ego and make other people better?</li>
</ul>
<p>Another coworker, Andy Maleh, wrote an intriguing blog post a month ago titled <a href="http://andymaleh.blogspot.com/2010/12/what-makes-developer-valuable-to-obtiva.html">Valuable Traits</a>. In it, he discusses four traits a software develop should possess to be valuable: caring about client needs, strive for effective communication, eager to learn, collaborate with others.</p>
<p>Note that none of these traits are technical skills, be a great Rails developer for example. Andy points out that &#8220;experience has taught me that soft skills trump hard technical skills&#8221;.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jonhoman.com/the-secret-of-developing-software/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Background Jobs in Rails with Resque</title>
		<link>http://blog.jonhoman.com/background-jobs-in-rails-with-resque/</link>
		<comments>http://blog.jonhoman.com/background-jobs-in-rails-with-resque/#comments</comments>
		<pubDate>Fri, 28 Jan 2011 14:04:18 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[apprenticeship]]></category>
		<category><![CDATA[dev]]></category>

		<guid isPermaLink="false">http://blog.jonhoman.com/?p=296</guid>
		<description><![CDATA[It makes a lot of sense to move your long running processes like API calls, grabbing external data, and cpu-heavy calculations to a background process so your UI is more responsive as you no longer block when doing that long &#8230; <a href="http://blog.jonhoman.com/background-jobs-in-rails-with-resque/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>It makes a lot of sense to move your long running processes like API calls, grabbing external data, and cpu-heavy calculations to a background process so your UI is more responsive as you no longer block when doing that long running process. </p>
<p>I want to walk you through setting up Resque in a Rails application because I&#8217;ve been happy using Resque on my personal project.</p>
<p>To get started, let&#8217;s create a new Rails 3 application. I called my app feed_parser.</p>
<p><code>$ rails new feed_parser</code></p>
<p>Now we need the following to our Gemfile so Bundler will install Resque and its dependencies. At this point, your Gemfile should look something like this, plus a bunch of comments.</p>
<pre name="code" class="ruby">
source 'http://rubygems.org'

gem 'rails', '3.0.3'

gem 'sqlite3-ruby', :require => 'sqlite3'
gem 'resque'
</pre>
<p>Next, we need to do some configuration so Resque knows where our Redis server is. We will assume the Redis defaults here, but you&#8217;ll want to change this for anything more advanced than this tutorial. Put the following in a new file called &#8216;config/initializers/resque.rb&#8217; without the quotes.</p>
<pre name="code" class="ruby">
uri = URI.parse("redis://localhost:6379/")
Resque.redis = Redis.new(:host => uri.host, :port => uri.port,
                                          :password => uri.password)
</pre>
<p>Resque can talk to Redis to act with the queue. Let&#8217;s write the logic that we want to run when there is a job on the queue.</p>
<p>Let&#8217;s generate a controller that will act as our way of adding some work to the queue.</p>
<p><code>$ rails g controller feed parse</code></p>
<p>This command will a controller called <code>FeedController</code> with a blank action <code>parse</code>.</p>
<p>As you can see, there&#8217;s a warning about the standard Timeout class, yada, yada, yada. To stop that from show again, include the SystemTimer gem in our Gemfile. Your entire Gemfile should look like this:</p>
<pre name="code" class="ruby">
source 'http://rubygems.org'

gem 'rails', '3.0.3'

gem 'sqlite3-ruby', :require => 'sqlite3'
gem 'resque'
gem 'SystemTimer'
</pre>
<p>Now, we need to add the code that will add jobs to our queue. We&#8217;ll put that logic in the controller we just created, which should now look like this:</p>
<pre name="code" class="ruby">
class FeedController < ApplicationController
  def parse
    Resque.enqueue(FeedParser)
    render :text => "We are working on parsing our feed right now."
  end
end
</pre>
<p>Let&#8217;s start up our server and take a look at see what happens.</p>
<p><code>$ rails s</code></p>
<p>And point to your browser to <a href="http://localhost:3000/feed/parse">http://localhost:3000/feed/parse</a>. Notice the error that we see: &#8220;Connection refused &#8211; Unable to connect to Redis on localhost:6379&#8243;. We need to install redis. </p>
<p>If you have homebrew:</p>
<p><code>brew install redis</code></p>
<p>Otherwise follow the instructions on the Redis&#8217; <a href="http://redis.io/download">homepage</a>.</p>
<p>Now you should be able to start the redis server:</p>
<p><code>$ redis-server</code></p>
<p>Now when you visit <a href="http://localhost:3000/feed/parse">http://localhost:3000/feed/parse</a> again, you should see our message that we are working on parsing the feed.</p>
<p>We can tell our system to put jobs on the queue, but we haven&#8217;t specified what those jobs should do. Create a file called feed_parser.rb under app/workers with this:</p>
<pre name="code" class="ruby">
class FeedParser
  @queue = :feeds

  def self.perform()
    parsed_feed = Feedzirra::Feed.fetch_and_parse("http://feeds.feedburner.com/JonHoman.com")
    first = parsed_feed.entries.first
    puts "Title: #{first.title}"
  end
end
</pre>
<p>We need to add another gem to our Gemfile since we now have a dependency on Feedzirra.</p>
<pre name="code" class="ruby">
source 'http://rubygems.org'

gem 'rails', '3.0.3'

gem 'sqlite3-ruby', :require => 'sqlite3'
gem 'resque'
gem 'SystemTimer'
gem 'feedzirra'
</pre>
<p>Now you might be wonder how do we know for sure that our job really made it to the queue? Well, thankfully Resque ships with a cool Sinatra administration app that allows us to inspect the current status of queues, workers, etc. Since both Rails and Sinatra are Rack apps, we can tell Rails to route certain web requests to Resque&#8217;s Sinatra app. </p>
<p>Edit your config.ru file. Note that if you named your Rails application something other than FeedParser you will need to change &#8216;FeedParser::Application&#8217; to &#8216;YourAppName::Application&#8217;.</p>
<pre name="code" class="ruby">
require ::File.expand_path('../config/environment',  __FILE__)

require 'resque/server'
run Rack::URLMap.new \
  "/" => FeedParser::Application,
  "/resque" => Resque::Server.new
</pre>
<p>We can now view the administration UI that ship with Resque by going to <a href="http://localhost:3000/resque">http://localhost:3000/resque</a>. As you can see, you have jobs in the feeds queue, but no workers started. Let&#8217;s do that now.</p>
<p>Create lib/tasks/resque.rake and add the following:</p>
<pre name="code" class="ruby">
require 'resque/tasks'

task "resque:setup" => :environment
</pre>
<p>The worker is a rake task that runs forever (or until you kill it) and, by default, checks the queue for new jobs every five seconds.</p>
<p>Start the worker in a terminal window:</p>
<p><code>$ rake resque:work QUEUE=*</code></p>
<p>You should see the output of your job, which is the title of my blog feed.</p>
<p>Hope you this helps you get started using Resque in your Rails applications. If you have any questions, please leave a comment and I&#8217;ll try to answer you.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jonhoman.com/background-jobs-in-rails-with-resque/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 0.311 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2012-03-16 23:23:51 -->
