Skip to content

Commit

Permalink
Job.validate! => Resque.validate
Browse files Browse the repository at this point in the history
  • Loading branch information
defunkt committed Mar 17, 2011
1 parent b8220b2 commit 06b3936
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
12 changes: 10 additions & 2 deletions lib/resque.rb
Expand Up @@ -273,8 +273,16 @@ def reserve(queue)
# If no queue can be inferred this method will raise a `Resque::NoQueueError`
#
# If given klass is nil this method will raise a `Resque::NoClassError`
def validate!(klass)
Job.validate!(klass)
def validate(klass, queue = nil)
queue ||= queue_from_class(klass)

if !queue
raise NoQueueError.new("Jobs must be placed onto a queue.")
end

if klass.to_s.empty?
raise NoClassError.new("Jobs must be given a class.")
end
end


Expand Down
14 changes: 1 addition & 13 deletions lib/resque/job.rb
Expand Up @@ -40,7 +40,7 @@ def initialize(queue, payload)
#
# Raises an exception if no queue or class is given.
def self.create(queue, klass, *args)
validate!(klass, queue)
Resque.validate(klass, queue)

if Resque.inline?
constantize(klass).perform(*decode(encode(args)))
Expand Down Expand Up @@ -98,18 +98,6 @@ def self.reserve(queue)
new(queue, payload)
end


# Validates if the given klass could be a valid Resque job
def self.validate!(klass, queue = Resque.queue_from_class(klass))
if !queue
raise NoQueueError.new("Jobs must be placed onto a queue.")
end

if klass.to_s.empty?
raise NoClassError.new("Jobs must be given a class.")
end
end

# Attempts to perform the work represented by this job instance.
# Calls #perform on the class given in the payload with the
# arguments given in the payload.
Expand Down
2 changes: 1 addition & 1 deletion test/resque_test.rb
Expand Up @@ -130,7 +130,7 @@

test "validates job for queue presence" do
assert_raises Resque::NoQueueError do
Resque.validate!(SomeJob)
Resque.validate(SomeJob)
end
end

Expand Down

0 comments on commit 06b3936

Please sign in to comment.