diff --git a/README.markdown b/README.markdown index 882ae10..4d349b2 100644 --- a/README.markdown +++ b/README.markdown @@ -2,7 +2,7 @@ An App to Give You *Just* Enough to Read on Your Commute. -Use it: [http://trippyapp.com](http://trippyapp.com). [Read about it](http://www.shhhaw.com/2010/12/introducing-trippy-an-app-to-give-you-just-enough-to-read-on-your-commute.php) +Use it: [http://trippyapp.com](http://trippyapp.com). [Read about it](http://www.shhhaw.com/2010/12/introducing-trippy-an-app-to-give-you-just-enough-to-read-on-your-commute.php) Built at TimesOpen [hack day](http://www.nytimes.com/marketing/timesopen/hackday.html) 2010 diff --git a/Rakefile b/Rakefile index 4f952bd..dab8b0f 100644 --- a/Rakefile +++ b/Rakefile @@ -4,7 +4,7 @@ require File.dirname(__FILE__) + "/vendor/delayed_job/tasks/tasks" namespace :db do task :migrate do ActiveRecord::Migrator.migrate( - 'db/migrate', + 'db/migrate', ENV["VERSION"] ? ENV["VERSION"].to_i : nil ) end diff --git a/lib/reader.rb b/lib/reader.rb index 7f3c4a9..cd11e0c 100644 --- a/lib/reader.rb +++ b/lib/reader.rb @@ -110,7 +110,7 @@ def select_articles(origin,destination,twitter_account,activity = nil,geo = nil) def check_job_status return nil if Delayed::Job.all.empty? - + jobs = Delayed::Job.all.size error = Delayed::Job.all.first.last_error ? Delayed::Job.all.first.last_error.to_s.gsub(/\\n|\n|\{/,'
') : nil if error diff --git a/misc/ec2.sh b/misc/ec2.sh index 0a3c56f..b595339 100644 --- a/misc/ec2.sh +++ b/misc/ec2.sh @@ -22,7 +22,7 @@ apt-get -y install mysql-server apt-get -y install mysql-client apt-get -y install libmysql-ruby libmysqlclient-dev apt-get -y install sqlite3 libsqlite3-dev libsqlite3-ruby1.8 libdbd-sqlite3-ruby1.8 -apt-get -y install libssl-dev +apt-get -y install libssl-dev apt-get -y install libcurl4-openssl-dev apt-get -y install libxslt-dev libxml2-dev apt-get -y install zip unzip diff --git a/public/medium.css b/public/medium.css index 0734e31..743a835 100644 --- a/public/medium.css +++ b/public/medium.css @@ -11,7 +11,7 @@ h2.label { display: block; } input.input_field { - margin-left: 12px; + margin-left: 12px; width:95%; } diff --git a/public/small.css b/public/small.css index 9077ef5..872d7f8 100644 --- a/public/small.css +++ b/public/small.css @@ -14,9 +14,9 @@ h2.label { display: block; } input.input_field { - margin-left: 12px; + margin-left: 12px; width:95%; - + } #articles { diff --git a/public/style.css b/public/style.css index 4c2cadd..41531b5 100644 --- a/public/style.css +++ b/public/style.css @@ -29,7 +29,7 @@ h2.label { margin: 5px 10px; font-family: helvetica,arial,sans-serif; font-size: 20px; - display: inline; + display: inline; float:left; clear:both; } diff --git a/public/trippy.js b/public/trippy.js index ca23257..2ee1dc5 100644 --- a/public/trippy.js +++ b/public/trippy.js @@ -18,7 +18,7 @@ $(function(){ $('#destination_field').attr("disabled", "disabled"); } }); - + // Add previous answers if they exist store(function(storage){ $('#destination_field').val(storage["trippy-destination"]); @@ -33,7 +33,7 @@ $(function(){ storage["trippy-twitter"] = $('#twitter_name').val(); }); }); - + $('#gps').click(function(){ navigator.geolocation.getCurrentPosition( function(pos){ @@ -78,10 +78,10 @@ var Trippy = { "you can read " + data["articles"]["articles"].length + " articles"); } }); - + }, stopJobChecker : function() { clearInterval(window.job_checker); } - + } diff --git a/vendor/delayed_job/README.textile b/vendor/delayed_job/README.textile index 9dd0a57..430b229 100644 --- a/vendor/delayed_job/README.textile +++ b/vendor/delayed_job/README.textile @@ -1,6 +1,6 @@ h1. Delayed::Job -Delated_job (or DJ) encapsulates the common pattern of asynchronously executing longer tasks in the background. +Delated_job (or DJ) encapsulates the common pattern of asynchronously executing longer tasks in the background. It is a direct extraction from Shopify where the job table is responsible for a multitude of core tasks. Amongst those tasks are: @@ -9,12 +9,12 @@ It is a direct extraction from Shopify where the job table is responsible for a * http downloads * updating smart collections * updating solr, our search server, after product changes -* batch imports -* spam checks - +* batch imports +* spam checks + h2. Setup - -The library evolves around a delayed_jobs table which looks as follows: + +The library evolves around a delayed_jobs table which looks as follows: create_table :delayed_jobs, :force => true do |table| table.integer :priority, :default => 0 # Allows some jobs to jump to the front of the queue @@ -54,37 +54,37 @@ Note: If your error messages are long, consider changing last_error field to a : h2. Usage Jobs are simple ruby objects with a method called perform. Any object which responds to perform can be stuffed into the jobs table. -Job objects are serialized to yaml so that they can later be resurrected by the job runner. +Job objects are serialized to yaml so that they can later be resurrected by the job runner. class NewsletterJob < Struct.new(:text, :emails) def perform emails.each { |e| NewsletterMailer.deliver_text_to_email(text, e) } - end - end - + end + end + Delayed::Job.enqueue NewsletterJob.new('lorem ipsum...', Customers.find(:all).collect(&:email)) - -There is also a second way to get jobs in the queue: send_later. - - BatchImporter.new(Shop.find(1)).send_later(:import_massive_csv, massive_csv) - +There is also a second way to get jobs in the queue: send_later. + + + BatchImporter.new(Shop.find(1)).send_later(:import_massive_csv, massive_csv) + This will simply create a Delayed::PerformableMethod job in the jobs table which serializes all the parameters you pass to it. There are some special smarts for active record objects which are stored as their text representation and loaded from the database fresh when the job is actually run later. - - + + h2. Running the jobs -You can invoke @rake jobs:work@ which will start working off jobs. You can cancel the rake task with @CTRL-C@. +You can invoke @rake jobs:work@ which will start working off jobs. You can cancel the rake task with @CTRL-C@. You can also run by writing a simple @script/job_runner@, and invoking it externally: - +

   #!/usr/bin/env ruby
   require File.dirname(__FILE__) + '/../config/environment'
-  
-  Delayed::Worker.new.start  
+
+  Delayed::Worker.new.start
 
Workers can be running on any computer, as long as they have access to the database and their clock is in sync. You can even @@ -99,9 +99,9 @@ You can invoke @rake jobs:clear@ to delete all jobs in the queue. h3. Changes -* 1.7.0: Added failed_at column which can optionally be set after a certain amount of failed job attempts. By default failed job attempts are destroyed after about a month. +* 1.7.0: Added failed_at column which can optionally be set after a certain amount of failed job attempts. By default failed job attempts are destroyed after about a month. -* 1.6.0: Renamed locked_until to locked_at. We now store when we start a given job instead of how long it will be locked by the worker. This allows us to get a reading on how long a job took to execute. +* 1.6.0: Renamed locked_until to locked_at. We now store when we start a given job instead of how long it will be locked by the worker. This allows us to get a reading on how long a job took to execute. * 1.5.0: Job runners can now be run in parallel. Two new database columns are needed: locked_until and locked_by. This allows us to use pessimistic locking instead of relying on row level locks. This enables us to run as many worker processes as we need to speed up queue processing. diff --git a/vendor/delayed_job/lib/delayed/job.rb b/vendor/delayed_job/lib/delayed/job.rb index 792986d..af3374f 100644 --- a/vendor/delayed_job/lib/delayed/job.rb +++ b/vendor/delayed_job/lib/delayed/job.rb @@ -109,7 +109,7 @@ def self.enqueue(*args, &block) unless object.respond_to?(:perform) || block_given? raise ArgumentError, 'Cannot enqueue items which do not respond to perform' end - + priority = args.first || 0 run_at = args[1] diff --git a/vendor/delayed_job/lib/delayed/message_sending.rb b/vendor/delayed_job/lib/delayed/message_sending.rb index ed75dda..7351ca0 100644 --- a/vendor/delayed_job/lib/delayed/message_sending.rb +++ b/vendor/delayed_job/lib/delayed/message_sending.rb @@ -3,7 +3,7 @@ module MessageSending def send_later(method, *args) Delayed::Job.enqueue Delayed::PerformableMethod.new(self, method.to_sym, args) end - + module ClassMethods def handle_asynchronously(method) without_name = "#{method}_without_send_later" @@ -13,5 +13,5 @@ def handle_asynchronously(method) alias_method_chain method, :send_later end end - end + end end \ No newline at end of file diff --git a/vendor/delayed_job/lib/delayed/performable_method.rb b/vendor/delayed_job/lib/delayed/performable_method.rb index 18bc77a..2718001 100644 --- a/vendor/delayed_job/lib/delayed/performable_method.rb +++ b/vendor/delayed_job/lib/delayed/performable_method.rb @@ -10,14 +10,14 @@ def initialize(object, method, args) self.args = args.map { |a| dump(a) } self.method = method.to_sym end - - def display_name + + def display_name case self.object when CLASS_STRING_FORMAT then "#{$1}.#{method}" when AR_STRING_FORMAT then "#{$1}##{method}" else "Unknown##{method}" - end - end + end + end def perform load(object).send(method, *args.map{|a| load(a)}) diff --git a/vendor/delayed_job/lib/delayed_job.rb b/vendor/delayed_job/lib/delayed_job.rb index 482cb2f..7a6cd2d 100644 --- a/vendor/delayed_job/lib/delayed_job.rb +++ b/vendor/delayed_job/lib/delayed_job.rb @@ -5,7 +5,7 @@ require File.dirname(__FILE__) + '/delayed/job' require File.dirname(__FILE__) + '/delayed/worker' -Object.send(:include, Delayed::MessageSending) +Object.send(:include, Delayed::MessageSending) Module.send(:include, Delayed::MessageSending::ClassMethods) if defined?(Merb::Plugins) diff --git a/vendor/delayed_job/spec/database.rb b/vendor/delayed_job/spec/database.rb index 505b06f..510a81b 100644 --- a/vendor/delayed_job/spec/database.rb +++ b/vendor/delayed_job/spec/database.rb @@ -7,7 +7,7 @@ require File.dirname(__FILE__) + '/../init' require 'spec' - + ActiveRecord::Base.logger = Logger.new('/tmp/dj.log') ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => '/tmp/jobs.sqlite') ActiveRecord::Migration.verbose = false @@ -35,8 +35,8 @@ # Purely useful for test cases... class Story < ActiveRecord::Base - def tell; text; end + def tell; text; end def whatever(n, _); tell*n; end - + handle_asynchronously :whatever end diff --git a/vendor/delayed_job/spec/delayed_method_spec.rb b/vendor/delayed_job/spec/delayed_method_spec.rb index e3911dc..8fb15ae 100644 --- a/vendor/delayed_job/spec/delayed_method_spec.rb +++ b/vendor/delayed_job/spec/delayed_method_spec.rb @@ -5,7 +5,7 @@ class SimpleJob def perform; @@runs += 1; end end -class RandomRubyObject +class RandomRubyObject def say_hello 'hello' end @@ -108,15 +108,15 @@ def read(story) job.payload_object.method.should == :read job.payload_object.args.should == ["AR:Story:#{story.id}"] job.payload_object.perform.should == 'Epilog: Once upon...' - end - + end + it "should call send later on methods which are wrapped with handle_asynchronously" do story = Story.create :text => 'Once upon...' - + Delayed::Job.count.should == 0 - + story.whatever(1, 5) - + Delayed::Job.count.should == 1 job = Delayed::Job.find(:first) job.payload_object.class.should == Delayed::PerformableMethod diff --git a/vendor/delayed_job/spec/job_spec.rb b/vendor/delayed_job/spec/job_spec.rb index b88e738..6f062db 100644 --- a/vendor/delayed_job/spec/job_spec.rb +++ b/vendor/delayed_job/spec/job_spec.rb @@ -8,24 +8,24 @@ def perform; @@runs += 1; end class ErrorJob cattr_accessor :runs; self.runs = 0 def perform; raise 'did not work'; end -end +end module M class ModuleJob cattr_accessor :runs; self.runs = 0 - def perform; @@runs += 1; end + def perform; @@runs += 1; end end - + end describe Delayed::Job do - before do + before do Delayed::Job.max_priority = nil - Delayed::Job.min_priority = nil - + Delayed::Job.min_priority = nil + Delayed::Job.delete_all end - + before(:each) do SimpleJob.runs = 0 end @@ -69,8 +69,8 @@ def perform; @@runs += 1; end SimpleJob.runs.should == 1 end - - + + it "should work with eval jobs" do $eval_job_ran = false @@ -83,7 +83,7 @@ def perform; @@runs += 1; end $eval_job_ran.should == true end - + it "should work with jobs in modules" do M::ModuleJob.runs.should == 0 @@ -92,7 +92,7 @@ def perform; @@runs += 1; end M::ModuleJob.runs.should == 1 end - + it "should re-schedule by about 1 second at first and increment this more and more minutes when it fails to execute properly" do Delayed::Job.enqueue ErrorJob.new Delayed::Job.work_off(1) @@ -147,7 +147,7 @@ def perform; @@runs += 1; end job.should_receive(:attempt_to_load).with('Delayed::JobThatDoesNotExist').and_return(true) lambda { job.payload_object.perform }.should raise_error(Delayed::DeserializationError) end - + it "should be failed if it failed more than MAX_ATTEMPTS times and we don't want to destroy jobs" do default = Delayed::Job.destroy_failed_jobs Delayed::Job.destroy_failed_jobs = false @@ -189,8 +189,8 @@ def perform; @@runs += 1; end it "should allow a second worker to get exclusive access if the timeout has passed" do @job.lock_exclusively!(1.minute, 'worker2').should == true - end - + end + it "should be able to get access to the task if it was started more then max_age ago" do @job.locked_at = 5.hours.ago @job.save @@ -217,9 +217,9 @@ def perform; @@runs += 1; end @job.lock_exclusively! 5.minutes, 'worker1' @job.lock_exclusively! 5.minutes, 'worker1' @job.lock_exclusively! 5.minutes, 'worker1' - end - end - + end + end + context "#name" do it "should be the class name of the job that was enqueued" do Delayed::Job.create(:payload_object => ErrorJob.new ).name.should == 'ErrorJob' @@ -231,66 +231,66 @@ def perform; @@runs += 1; end end it "should be the instance method that will be called if its a performable method object" do - story = Story.create :text => "..." - + story = Story.create :text => "..." + story.send_later(:save) - + Delayed::Job.last.name.should == 'Story#save' end end - + context "worker prioritization" do - + before(:each) do Delayed::Job.max_priority = nil - Delayed::Job.min_priority = nil + Delayed::Job.min_priority = nil end - + it "should only work_off jobs that are >= min_priority" do Delayed::Job.min_priority = -5 Delayed::Job.max_priority = 5 SimpleJob.runs.should == 0 - + Delayed::Job.enqueue SimpleJob.new, -10 Delayed::Job.enqueue SimpleJob.new, 0 Delayed::Job.work_off - + SimpleJob.runs.should == 1 end - + it "should only work_off jobs that are <= max_priority" do Delayed::Job.min_priority = -5 Delayed::Job.max_priority = 5 SimpleJob.runs.should == 0 - + Delayed::Job.enqueue SimpleJob.new, 10 Delayed::Job.enqueue SimpleJob.new, 0 Delayed::Job.work_off SimpleJob.runs.should == 1 - end - + end + end - + context "when pulling jobs off the queue for processing, it" do before(:each) do @job = Delayed::Job.create( - :payload_object => SimpleJob.new, - :locked_by => 'worker1', + :payload_object => SimpleJob.new, + :locked_by => 'worker1', :locked_at => Delayed::Job.db_time_now - 5.minutes) end it "should leave the queue in a consistent state and not run the job if locking fails" do - SimpleJob.runs.should == 0 + SimpleJob.runs.should == 0 @job.stub!(:lock_exclusively!).with(any_args).once.and_return(false) Delayed::Job.should_receive(:find_available).once.and_return([@job]) Delayed::Job.work_off(1) SimpleJob.runs.should == 0 end - + end - + context "while running alongside other workers that locked jobs, it" do before(:each) do Delayed::Job.worker_name = 'worker1' @@ -341,5 +341,5 @@ def perform; @@runs += 1; end end end - + end diff --git a/vendor/rack-esi/COPYING.txt b/vendor/rack-esi/COPYING.txt index 323c643..83928c1 100644 --- a/vendor/rack-esi/COPYING.txt +++ b/vendor/rack-esi/COPYING.txt @@ -1,6 +1,6 @@ Rack::ESI -Copyright (c) 2008 Christoffer Sawicki +Copyright (c) 2008 Christoffer Sawicki Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to @@ -8,13 +8,13 @@ deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.