perform_later 1.0.8 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,9 +20,10 @@ module ObjectPerformLater
20
20
  private
21
21
  def perform_later_enqueue(worker, queue, method, args)
22
22
  if PerformLater.config.enabled?
23
- Resque::Job.create(queue, worker, self.name, method, args)
23
+ Resque::Job.create(queue, worker, self.name, method, *args)
24
24
  else
25
- self.send(method, args)
25
+ args = PerformLater::ArgsParser.args_from_resque(args)
26
+ self.send(method, *args)
26
27
  end
27
28
  end
28
29
  end
@@ -1,3 +1,3 @@
1
1
  module PerformLater
2
- VERSION = "1.0.8"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -4,7 +4,7 @@ module PerformLater
4
4
  class LoneWorker
5
5
  def self.perform(klass, id, method, args)
6
6
  # Remove the loner flag from redis
7
- digest = PerformLater::PayloadHelper.get_digest(klass, method_name, args)
7
+ digest = PerformLater::PayloadHelper.get_digest(klass, method, args)
8
8
  Resque.redis.del(digest)
9
9
 
10
10
  args = PerformLater::ArgsParser.args_from_resque(args)
@@ -46,11 +46,12 @@ module Resque::Plugins::Later::Method
46
46
  end
47
47
 
48
48
  private
49
- def enqueue_in_resque_or_send(worker, queue, method, args)
49
+ def enqueue_in_resque_or_send(worker, queue, method, *args)
50
50
  if PerformLater.config.enabled?
51
51
  Resque::Job.create(queue, worker, self.class.name, self.id, method, *args)
52
52
  else
53
- self.send(method, args)
53
+ args = PerformLater::ArgsParser.args_from_resque(args)
54
+ self.send(method, *args)
54
55
  end
55
56
  end
56
57
  end
@@ -2,7 +2,11 @@ require 'spec_helper'
2
2
 
3
3
  class DummyClass
4
4
  def self.do_something_really_heavy
5
-
5
+
6
+ end
7
+
8
+ def self.do_something_with_string(value)
9
+ value
6
10
  end
7
11
  end
8
12
 
@@ -36,5 +40,11 @@ describe ObjectPerformLater do
36
40
  Resque.peek(:generic, 0, 20).length.should == 1
37
41
  end
38
42
 
39
-
43
+ describe :perform_later! do
44
+ it "should pass the correct value (String)" do
45
+ PerformLater.config.stub!(:enabled?).and_return(false)
46
+ DummyClass.should_receive(:do_something_with_string).with("Avi Tzurel")
47
+ DummyClass.perform_later!(:generic, :do_something_with_string, "Avi Tzurel")
48
+ end
49
+ end
40
50
  end
@@ -58,6 +58,22 @@ describe Resque::Plugins::Later::Method do
58
58
  user.should respond_to(:now_long_running_method)
59
59
  end
60
60
 
61
+ describe :perform_later! do
62
+ it "should send the correct params on the method (with hash)" do
63
+ PerformLater.config.stub!(:enabled?).and_return(false)
64
+ user = User.create
65
+ user.should_receive(:method_with_hash_as_option).with({:some_option => "Brown fox"})
66
+ user.perform_later!(:generic, :method_with_hash_as_option, :some_option => "Brown fox")
67
+ end
68
+
69
+ it "should send the correct params on the method (with integer)" do
70
+ PerformLater.config.stub!(:enabled?).and_return(false)
71
+ user = User.create
72
+ user.should_receive(:method_with_integer_option).with(1).and_return(1)
73
+ user.perform_later!(:generic, :method_with_integer_option, 1)
74
+ end
75
+ end
76
+
61
77
 
62
78
 
63
79
 
@@ -13,4 +13,13 @@ class User < ActiveRecord::Base
13
13
  # Your code here
14
14
  end
15
15
  later :lonely_long_running_method, :loner => true, queue: :some_queue_name
16
+
17
+ def method_with_hash_as_option(options = {})
18
+ options[:some_option]
19
+ end
20
+
21
+ def method_with_integer_option(integer)
22
+ integer
23
+ end
24
+
16
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: perform_later
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: