Skip to content

Commit

Permalink
Removing whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
bryckbost committed Mar 30, 2012
1 parent 7064b40 commit 5d21f72
Show file tree
Hide file tree
Showing 22 changed files with 79 additions and 79 deletions.
2 changes: 1 addition & 1 deletion MIT-LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOa AND
NONINFRINGEMENT. IN NO EVENT SaALL THE AUTHORS OR COPYRIGHT HOLDERS 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.
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2 changes: 1 addition & 1 deletion contrib/delayed_job.monitrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
check process delayed_job
with pidfile /var/www/apps/{app_name}/shared/pids/delayed_job.pid
start program = "/usr/bin/env RAILS_ENV=production /var/www/apps/{app_name}/current/script/delayed_job start"
stop program = "/usr/bin/env RAILS_ENV=production /var/www/apps/{app_name}/current/script/delayed_job stop"
stop program = "/usr/bin/env RAILS_ENV=production /var/www/apps/{app_name}/current/script/delayed_job stop"
6 changes: 3 additions & 3 deletions contrib/delayed_job_multiple.monitrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ check process delayed_job_0
with pidfile /var/www/apps/{app_name}/shared/pids/delayed_job.0.pid
start program = "/usr/bin/env RAILS_ENV=production /var/www/apps/{app_name}/current/script/delayed_job start -i 0"
stop program = "/usr/bin/env RAILS_ENV=production /var/www/apps/{app_name}/current/script/delayed_job stop -i 0"

check process delayed_job_1
with pidfile /var/www/apps/{app_name}/shared/pids/delayed_job.1.pid
start program = "/usr/bin/env RAILS_ENV=production /var/www/apps/{app_name}/current/script/delayed_job start -i 1"
stop program = "/usr/bin/env RAILS_ENV=production /var/www/apps/{app_name}/current/script/delayed_job stop -i 1"

check process delayed_job_2
with pidfile /var/www/apps/{app_name}/shared/pids/delayed_job.2.pid
start program = "/usr/bin/env RAILS_ENV=production /var/www/apps/{app_name}/current/script/delayed_job start -i 2"
stop program = "/usr/bin/env RAILS_ENV=production /var/www/apps/{app_name}/current/script/delayed_job stop -i 2"
stop program = "/usr/bin/env RAILS_ENV=production /var/www/apps/{app_name}/current/script/delayed_job stop -i 2"
6 changes: 3 additions & 3 deletions lib/delayed/backend/shared_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -414,13 +414,13 @@ def create_job(opts = {})
story.update_attributes :text => 'goodbye'
job.reload.payload_object.object.text.should == 'goodbye'
end

it "should raise error ArgumentError the record is not persisted" do
story = Story.new(:text => 'hello')
lambda {
story.delay.tell
story.delay.tell
}.should raise_error(ArgumentError, "Jobs cannot be created for records before they've been persisted")

end

it "should raise deserialization error for destroyed records" do
Expand Down
2 changes: 1 addition & 1 deletion lib/delayed/deserialization_error.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Delayed
class DeserializationError < StandardError
end
end
end
48 changes: 24 additions & 24 deletions lib/delayed/lifecycle.rb
Original file line number Diff line number Diff line change
@@ -1,73 +1,73 @@
module Delayed
class InvalidCallback < Exception; end

class Lifecycle
EVENTS = {
:enqueue => [:job],
:execute => [:worker],
:loop => [:worker],
:perform => [:worker, :job],
:error => [:worker, :job],
:failure => [:worker, :job],
:enqueue => [:job],
:execute => [:worker],
:loop => [:worker],
:perform => [:worker, :job],
:error => [:worker, :job],
:failure => [:worker, :job],
:invoke_job => [:job]
}

def initialize
@callbacks = EVENTS.keys.inject({}) { |hash, e| hash[e] = Callback.new; hash }
end

def before(event, &block)
add(:before, event, &block)
end

def after(event, &block)
add(:after, event, &block)
end

def around(event, &block)
add(:around, event, &block)
end

def run_callbacks(event, *args, &block)
missing_callback(event) unless @callbacks.has_key?(event)

unless EVENTS[event].size == args.size
raise ArgumentError, "Callback #{event} expects #{EVENTS[event].size} parameter(s): #{EVENTS[event].join(', ')}"
end

@callbacks[event].execute(*args, &block)
end

private

def add(type, event, &block)
missing_callback(event) unless @callbacks.has_key?(event)

@callbacks[event].add(type, &block)
end

def missing_callback(event)
raise InvalidCallback, "Unknown callback event: #{event}"
end
end

class Callback
def initialize
@before = []
@after = []

# Identity proc. Avoids special cases when there is no existing around chain.
@around = lambda { |*args, &block| block.call(*args) }
end
def execute(*args, &block)

def execute(*args, &block)
@before.each { |c| c.call(*args) }
result = @around.call(*args, &block)
@after.each { |c| c.call(*args) }
result
end
def add(type, &callback)

def add(type, &callback)
case type
when :before
@before << callback
Expand All @@ -81,4 +81,4 @@ def add(type, &callback)
end
end
end
end
end
4 changes: 2 additions & 2 deletions lib/delayed/performable_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ class PerformableMethod

def initialize(object, method_name, args)
raise NoMethodError, "undefined method `#{method_name}' for #{object.inspect}" unless object.respond_to?(method_name, true)

if defined?(ActiveRecord) && object.kind_of?(ActiveRecord::Base)
raise(ArgumentError, 'Jobs cannot be created for records before they\'ve been persisted') if object.attributes[object.class.primary_key].nil?
end

self.object = object
self.args = args
self.method_name = method_name.to_sym
Expand Down
2 changes: 1 addition & 1 deletion lib/delayed/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ def initialize
self.class.callback_block.call(Delayed::Worker.lifecycle) if self.class.callback_block
end
end
end
end
6 changes: 3 additions & 3 deletions lib/delayed/plugins/clear_locks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ class ClearLocks < Plugin
lifecycle.around(:execute) do |worker, &block|
begin
block.call(worker)
ensure
ensure
Delayed::Job.clear_locks!(worker.name)
end
end
end
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/delayed/psych_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def visit_Psych_Nodes_Scalar(o)
@ss.tokenize o.value
end
end

def visit_Psych_Nodes_Mapping_with_class(object)
return revive(Psych.load_tags[object.tag], object) if Psych.load_tags[object.tag]

Expand Down
8 changes: 4 additions & 4 deletions lib/delayed/recipes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
def rails_env
fetch(:rails_env, false) ? "RAILS_ENV=#{fetch(:rails_env)}" : ''
end

def args
fetch(:delayed_job_args, "")
end

def roles
fetch(:delayed_job_server_role, :app)
end

desc "Stop the delayed_job process"
task :stop, :roles => lambda { roles } do
run "cd #{current_path};#{rails_env} script/delayed_job stop"
Expand All @@ -47,4 +47,4 @@ def roles
run "cd #{current_path};#{rails_env} script/delayed_job restart #{args}"
end
end
end
end
2 changes: 1 addition & 1 deletion lib/delayed/serialization/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ def to_yaml_properties
['@attributes']
end
end
end
end
2 changes: 1 addition & 1 deletion spec/autoloaded/clazz.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ class Clazz
def perform
end
end
end
end
2 changes: 1 addition & 1 deletion spec/autoloaded/instance_clazz.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ class InstanceClazz
def perform
end
end
end
end
2 changes: 1 addition & 1 deletion spec/autoloaded/instance_struct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ class InstanceStruct < ::Struct.new(nil)
def perform
end
end
end
end
2 changes: 1 addition & 1 deletion spec/autoloaded/struct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ class Struct < ::Struct.new(nil)
def perform
end
end
end
end
38 changes: 19 additions & 19 deletions spec/delayed/backend/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,55 +15,55 @@ class Job
attr_accessor :locked_by
attr_accessor :failed_at
attr_accessor :queue

include Delayed::Backend::Base

cattr_accessor :id
self.id = 0

def initialize(hash = {})
self.attempts = 0
self.priority = 0
self.id = (self.class.id += 1)
hash.each{|k,v| send(:"#{k}=", v)}
end

@jobs = []
def self.all
@jobs
end
def self.count

def self.count
all.size
end

def self.delete_all
all.clear
end

def self.create(attrs = {})
new(attrs).tap do |o|
o.save
end
end

def self.create!(*args); create(*args); end

def self.clear_locks!(worker_name)
all.select{|j| j.locked_by == worker_name}.each {|j| j.locked_by = nil; j.locked_at = nil}
end

# Find a few candidate jobs to run (in case some immediately get locked by others).
def self.find_available(worker_name, limit = 5, max_run_time = Worker.max_run_time)
jobs = all.select do |j|
j.run_at <= db_time_now &&
jobs = all.select do |j|
j.run_at <= db_time_now &&
(j.locked_at.nil? || j.locked_at < db_time_now - max_run_time || j.locked_by == worker_name) &&
!j.failed?
end

jobs = jobs.select{|j| Worker.queues.include?(j.queue)} if Worker.queues.any?
jobs = jobs.select{|j| j.priority >= Worker.min_priority} if Worker.min_priority
jobs = jobs.select{|j| j.priority <= Worker.max_priority} if Worker.max_priority
jobs = jobs.select{|j| j.priority <= Worker.max_priority} if Worker.max_priority
jobs.sort_by{|j| [j.priority, j.run_at]}[0..limit-1]
end

Expand All @@ -83,25 +83,25 @@ def lock_exclusively!(max_run_time, worker)
def self.db_time_now
Time.current
end

def update_attributes(attrs = {})
attrs.each{|k,v| send(:"#{k}=", v)}
save
end

def destroy
self.class.all.delete(self)
end

def save
self.run_at ||= Time.current

self.class.all << self unless self.class.all.include?(self)
true
end

def save!; save; end

def reload
reset
self
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/bad_alias.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
foo: *bar
foo: *bar
2 changes: 1 addition & 1 deletion spec/lifecycle_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@
lifecycle.before(:execute, &callback)
expect { lifecycle.run_callbacks(:execute, 1,2,3) {} }.to raise_error(ArgumentError, /1 parameter/)
end
end
end
4 changes: 2 additions & 2 deletions spec/message_sending_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def tell
job.run_at.should == run_at
job.priority.should == 20
end

it "should not delay the job when delay_jobs is false" do
Delayed::Worker.delay_jobs = false
fairy_tail = FairyTail.new
Expand All @@ -99,7 +99,7 @@ def tell
}.should change(fairy_tail, :happy_ending).from(nil).to(true)
}.should_not change { Delayed::Job.count }
end

it "should delay the job when delay_jobs is true" do
Delayed::Worker.delay_jobs = true
fairy_tail = FairyTail.new
Expand Down
Loading

0 comments on commit 5d21f72

Please sign in to comment.