Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|\{/,'<br/>') : nil
if error
Expand Down
2 changes: 1 addition & 1 deletion misc/ec2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion public/medium.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ h2.label {
display: block; }

input.input_field {
margin-left: 12px;
margin-left: 12px;
width:95%;
}

Expand Down
4 changes: 2 additions & 2 deletions public/small.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ h2.label {
display: block; }

input.input_field {
margin-left: 12px;
margin-left: 12px;
width:95%;

}

#articles {
Expand Down
2 changes: 1 addition & 1 deletion public/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions public/trippy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"]);
Expand All @@ -33,7 +33,7 @@ $(function(){
storage["trippy-twitter"] = $('#twitter_name').val();
});
});

$('#gps').click(function(){
navigator.geolocation.getCurrentPosition(
function(pos){
Expand Down Expand Up @@ -78,10 +78,10 @@ var Trippy = {
"you can read " + data["articles"]["articles"].length + " articles");
}
});

},
stopJobChecker : function() {
clearInterval(window.job_checker);
}

}
46 changes: 23 additions & 23 deletions vendor/delayed_job/README.textile
Original file line number Diff line number Diff line change
@@ -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:

Expand All @@ -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
Expand Down Expand Up @@ -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:

<pre><code>
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/environment'
Delayed::Worker.new.start

Delayed::Worker.new.start
</code></pre>

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
Expand All @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion vendor/delayed_job/lib/delayed/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
4 changes: 2 additions & 2 deletions vendor/delayed_job/lib/delayed/message_sending.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -13,5 +13,5 @@ def handle_asynchronously(method)
alias_method_chain method, :send_later
end
end
end
end
end
8 changes: 4 additions & 4 deletions vendor/delayed_job/lib/delayed/performable_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)})
Expand Down
2 changes: 1 addition & 1 deletion vendor/delayed_job/lib/delayed_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions vendor/delayed_job/spec/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
12 changes: 6 additions & 6 deletions vendor/delayed_job/spec/delayed_method_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class SimpleJob
def perform; @@runs += 1; end
end

class RandomRubyObject
class RandomRubyObject
def say_hello
'hello'
end
Expand Down Expand Up @@ -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
Expand Down
Loading