perform_later 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -29,12 +29,12 @@ If you are using bundler, simply add
29
29
 
30
30
 
31
31
  ## Configuration
32
- You can configure `perform_later` exactly as you configure your rails app.
33
-
34
- Inside your `#{env}.rb` file (for example development.rb)
32
+ In an initializer, all you need to say is whether you want perform later to be enabled or not, typically, it will be something like this
35
33
 
36
34
  ```ruby
37
- config.later.enabled = true # this will default to false if unset
35
+ unless Rails.env.test?
36
+ PerformLater.config.later.enabled = true # this will default to false if unset
37
+ end
38
38
  ```
39
39
 
40
40
  ## Usage
@@ -1,14 +1,24 @@
1
1
  module ObjectPerformLater
2
2
 
3
3
  def perform_later(queue, method, *args)
4
- if PerformLater.config.enabled?
5
- args = PerformLater::ArgsParser.args_to_resque(args)
6
- Resque::Job.create(queue, PerformLater::Workers::Objects::Worker, self.name, method, *args)
7
- else
8
- self.send(method, *args)
9
- end
4
+ worker = PerformLater::Workers::Objects::Worker
5
+ perform_later_enqueue(worker, queue, method, args)
6
+ end
7
+
8
+ def perform_later!(queue, method, *args)
9
+ worker = PerformLater::Workers::Objects::LoneWorker
10
+ perform_later_enqueue(worker, queue, method, args)
10
11
  end
11
12
 
13
+ private
14
+ def perform_later_enqueue(worker, queue, method, args)
15
+ if PerformLater.config.enabled?
16
+ args = PerformLater::ArgsParser.args_to_resque(args)
17
+ Resque::Job.create(queue, worker, self.name, method, *args)
18
+ else
19
+ self.send(method, *args)
20
+ end
21
+ end
12
22
  end
13
23
 
14
24
  Object.send(:include, ObjectPerformLater)
@@ -1,5 +1,5 @@
1
1
  module PerformLater
2
2
  class Railtie < ::Rails::Railtie
3
- config.later = PerformLater::Config
3
+ config.perf_later = PerformLater::Config
4
4
  end
5
5
  end
@@ -1,3 +1,3 @@
1
1
  module PerformLater
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -1,5 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
+ class DummyClass
4
+ def self.do_something_really_heavy
5
+
6
+ end
7
+ end
8
+
3
9
  describe ObjectPerformLater do
4
10
  it "should insert a task into resque when the config is enabled" do
5
11
  Resque.redis = $redis
@@ -18,4 +24,17 @@ describe ObjectPerformLater do
18
24
 
19
25
  Resque.peek(:generic, 0, 20).length.should == 0
20
26
  end
27
+
28
+ it "should only add the method a single time to the queue" do
29
+ PerformLater.config.stub!(:enabled?).and_return(true)
30
+
31
+ DummyClass.perform_later!(:generic, :do_something_really_heavy)
32
+ DummyClass.perform_later!(:generic, :do_something_really_heavy)
33
+ DummyClass.perform_later!(:generic, :do_something_really_heavy)
34
+ DummyClass.perform_later!(:generic, :do_something_really_heavy)
35
+
36
+ Resque.peek(:generic, 0, 20).length.should == 1
37
+ end
38
+
39
+
21
40
  end
@@ -30,7 +30,7 @@ describe Resque::Plugins::Later::Method do
30
30
  user.lonely_long_running_method
31
31
  user.lonely_long_running_method
32
32
  user.lonely_long_running_method
33
- Resque.peek(:generic, 0, 20).length.should == 1
33
+ Resque.peek(:generic, 0, 20).length.should == 1
34
34
  end
35
35
  end
36
36
 
@@ -7,6 +7,7 @@ require "support/database_models"
7
7
  require "redis"
8
8
  require 'fakeredis/rspec'
9
9
  require 'simplecov'
10
+ require 'resque'
10
11
 
11
12
  SimpleCov.start
12
13
 
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.1
4
+ version: 1.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: